
VMA322
V. 02 – 08/05/2019
4
©Velleman nv
SPI_DIR = ( CE + SCK + CSN + MOSI);
SPI_DIR &=~ ( IRQ + MISO);
// attachInterrupt(1, _ISR, LOW);// interrupt enable
Serial.begin(9600);
init_io(); // Initialize IO port
unsigned char status=SPI_Read(STATUS);
Serial.print("status = ");
Serial.println(status,HEX); // There is read the mode’s status register, the default value should be ‘E’
Serial.println("*******************TX_Mode Start****************************");
TX_Mode(); // set TX mode
}
void loop()
{
int k = 0;
for(;;)
{
for(int i=0; i<32; i++)
tx_buf[i] = k++;
unsigned char status = SPI_Read(STATUS); // read register STATUS's value
if(status&TX_DS) // if receive data ready (TX_DS) interrupt
{
SPI_RW_Reg(FLUSH_TX,0);
SPI_Write_Buf(WR_TX_PLOAD,tx_buf,TX_PLOAD_WIDTH); // write playload to TX_FIFO
}
if(status&MAX_RT) // if receive data ready (MAX_RT) interrupt, this is
retransmit than SETUP_RETR
{
SPI_RW_Reg(FLUSH_TX,0);
SPI_Write_Buf(WR_TX_PLOAD,tx_buf,TX_PLOAD_WIDTH); // disable standy-mode
}
SPI_RW_Reg(WRSTATUS,status); // clear RX_DR or TX_DS or MAX_RT interrupt
flag
delay(1000);
}
}
//**************************************************
// Function: init_io();
// Description:
// flash led one time,chip enable(ready to TX or RX Mode),
// Spi disable,Spi clock line init high
//**************************************************
void init_io(void)
{
SPI_PORT&=~CE;
// chip enable
SPI_PORT|=CSN;
// Spi disable
SPI_PORT&=~SCK;
// Spi clock line init high
}
/**************************************************
* Function: SPI_RW();
*
* Description:
* Writes one unsigned char to nRF24L01, and return the unsigned char read