
VMA322
V. 02 – 08/05/2019
8
©Velleman nv
unsigned char rx_buf[TX_PLOAD_WIDTH];
unsigned char tx_buf[TX_PLOAD_WIDTH];
//***************************************************
void setup()
{
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("*****************RX_Mode start******************************R");
RX_Mode(); // set RX mode
}
void loop()
{
for(;;)
{
unsigned char status = SPI_Read(STATUS); // read register STATUS's value
if(status&RX_DR) // if receive data ready (TX_DS) interrupt
{
SPI_Read_Buf(RD_RX_PLOAD, rx_buf, TX_PLOAD_WIDTH); // read playload to rx_buf
SPI_RW_Reg(FLUSH_RX,0); // clear RX_FIFO
for(int i=0; i<32; i++)
{
Serial.print(" ");
Serial.print(rx_buf[i],HEX); // print rx_buf
}
Serial.println(" ");
}
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();