uint8_t* WriteReadToNrf(uint8_t ReadWrite, uint8_t reg, uint8_t *DataRW, uint8_t DataRWlength) { if(ReadWrite == W) { reg = W_REGISTER + reg; } static uint8_t ret[32]; _delay_us(10); CLEAR_CSN; _delay_us(10); WriteByteSPI(reg); _delay_us(10); int i; for(i = 0; i < DataRWlength; i++) { if(ReadWrite ==R && reg != W_TX_PAYLOAD) { ret[i] = WriteByteSPI(NOP); _delay_us(10); } else { WriteByteSPI(DataRW[i]); _delay_us(10); } } SET_CSN; return ret; }
void reset(void) { _delay_us(10); CLEAR_CSN; _delay_us(10); WriteByteSPI(W_REGISTER + STATUS); _delay_us(10); WriteByteSPI(0x70); _delay_us(10); SET_CSN; }
void WriteToNrf(uint8_t reg, uint8_t data) { _delay_us(10); CLEAR_CSN; _delay_us(10); WriteByteSPI(W_REGISTER + reg); _delay_us(10); WriteByteSPI(data); _delay_us(10); SET_CSN; }
uint8_t GetRegister(uint8_t reg) { _delay_us(10); CLEAR_CSN; _delay_us(10); WriteByteSPI(R_REGISTER + reg); _delay_us(10); reg=WriteByteSPI(NOP); _delay_us(10); SET_CSN; return reg; }
/* in SPI write mode CPOL=0 CPHA=0, write msb bit first, write msb byte first */ void _AD9911_write( uint8_t addr, uint32_t data ) { uint8_t AD9911_cmd, len; int i; if( addr > AD9911_MAXREG ) return; // SPI CPOL=0 CPHA=0 SPCR = (1<<SPE)|(1<<MSTR)|(0<<SPR1)|(0<<SPR0)|(0<<CPOL)|(0<<CPHA); PORTB &= ~(1<<0); // ss low AD9911_cmd = addr & AD9911_addressmask; if( addr > 7 || addr == 4 ) len = 4; else if( addr == 7 || addr == 5 || addr == 2 ) len = 2; else if( addr == 0 ) len = 1; else len = 3; WriteByteSPI( AD9911_cmd ); for(i=len-1;i >= 0;i--) { WriteByteSPI( (uint8_t)((data>>(8*i)) & 0xff) ); } PORTB |= (1<<0); // ss high }
/* in SPI read mode CPOL=1 CPHA=1, read msb bit first, read msb byte first */ void _AD9911_read( uint8_t addr, uint32_t *data ) { uint8_t AD9911_cmd, len; int i; if( addr > AD9911_MAXREG ) return; // SPI CPOL=1 CPHA=1 SPCR = (1<<SPE)|(1<<MSTR)|(0<<SPR1)|(0<<SPR0)|(1<<CPOL)|(1<<CPHA); PORTB &= ~(1<<0); // ss low AD9911_cmd = addr & AD9911_addressmask; AD9911_cmd |= AD9911_RWb; if( addr > 7 || addr == 4 ) len = 4; else if( addr == 7 || addr == 5 || addr == 2 ) len = 2; else if( addr == 0 ) len = 1; else len = 3; WriteByteSPI( AD9911_cmd ); *data = 0; for(i=len-1;i >= 0;i--) { *data |= ReadByteSPI(0)<<(8*i); } PORTB |= (1<<0); // ss high }
/*-------------------------------------------------------------------------------------------------- Name : LCD_writeData Description : Sends Data to display controller. Argument(s) : Data -> Data to be sent Return value : None. --------------------------------------------------------------------------------------------------*/ void LCD_writeData ( unsigned char Data ) { CLEAR_SCE_PIN; //enable LCD SET_DC_PIN; //set LCD in Data mode // Send data to display controller. WriteByteSPI(Data); SET_SCE_PIN; //disable LCD }
/*-------------------------------------------------------------------------------------------------- Name : LCD_writeCommand Description : Sends command to display controller. Argument(s) : command -> command to be sent Return value : None. --------------------------------------------------------------------------------------------------*/ void LCD_writeCommand ( unsigned char command ) { CLEAR_SCE_PIN; //enable LCD CLEAR_DC_PIN; //set LCD in command mode // Send data to display controller. WriteByteSPI(command); SET_SCE_PIN; //disable LCD }