You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
632 B

/*
* SPI.c
*
* Created: 24.10.2023 15:34:10
* Author: Katya
*/
#include "SPI.h"
void SPI_MasterInit(void) {
// Íàñòðîéêà ïèíà SS (PE2) êàê âûõîäà
DDRE |= (1 << PORTE2);
// Óñòàíîâêà SS â âûñîêîå ñîñòîÿíèå (íåàêòèâíûé)
PORTE |= (1 << PORTE2);
/* Set MOSI, SS and SCK output */
DDRE |= (1 << MOSI);
DDRC |= (1 << SCK) | (1 << SS);
/* Enable SPI, Master */
SPCR1 = (1 << SPE1) | (1 << MSTR1);
}
void SPI_MasterTransmit(uint8_t data) {
PORTC &= ~(1 << PORTC2); // íà÷àëî ïåðåäà÷è - íèçêèé óðîâåíü
SPDR1 = data;
while(!(SPSR1 & (1<<SPIF1)));
PORTC |= (1 << PORTC2); // êîíåö ïåðåäà÷è - âûñîêèé óðîâåíü
}