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.
|
|
|
|
/*
|
|
|
|
|
* SPI.c
|
|
|
|
|
*
|
|
|
|
|
* Created: 24.10.2023 15:34:10
|
|
|
|
|
* Author: Katya
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "SPI.h"
|
|
|
|
|
|
|
|
|
|
void SPI_MasterInit(void) {
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> SS (PE2) <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
DDRE |= (1 << PORTE2);
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> SS <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
|
|
|
|
|
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); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
SPDR1 = data;
|
|
|
|
|
while(!(SPSR1 & (1<<SPIF1)));
|
|
|
|
|
PORTC |= (1 << PORTC2); // <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
}
|