uint32_t getBigEndianExt(uint8_t *bytes){ uint8_t extb = *bytes; uint8_t msb = INC_THIS(bytes); uint8_t lsb = INC_THIS(bytes); return GET_EXT(extb,msb,lsb); }
uint8_t retf(uint8_t *opcode){ *pcToLoad = GET_EXT(mcu_pop(),mcu_pop(),mcu_pop()); return 1; }
void ThreadSPIXCallback (void const *argument) { uint8_t u8Data = 0, u8ExtData = 0; // End of TX part. //============================================================================== // Recovery NSS after sent data. if(u8Nss1Low == 0) { //============================================================================== // Send cmd first then data if(IS_DATA_EXIST(SPI1_TXCmdBuffer)) { if(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == SET) //If it's free to send data. { GET_EXT(SPI1_TXCmdBuffer, u8Data, u8ExtData); // Get data from ring buffer. switch(u8ExtData) { case SPI1_CMD_PIN: GPIO_ResetBits(GPIOA, GPIO_Pin_8);// PA8:D/C command = 0 break; case SPI1_NRF24CSN_PIN: GPIO_ResetBits(GPIOC, GPIO_Pin_4);// PC4: NRF24L01 CSN = 0 default: GPIO_SetBits(GPIOA, GPIO_Pin_8);// PA8:D/C data = 1 break; } GPIO_ResetBits(GPIOA, GPIO_Pin_4); // PA4:Turn on NSS.--> Normal high, active low. SPI_I2S_SendData(SPI1, u8Data); // Send data u8Nss1Low = 1; } } } else { if(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == RESET) //If it's free to send data. { GPIO_SetBits(GPIOA, GPIO_Pin_4); u8Nss1Low = 0; } } //============================================================================== // Recovery NSS after sent data. if(u8Nss2Low == 0) { //============================================================================== // Send cmd first then data if(IS_DATA_EXIST(SPI2_TXCmdBuffer)) { if(SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == SET) //If it's free to send data. { GET_EXT(SPI2_TXCmdBuffer, u8Data, u8ExtData); // Get data from ring buffer. switch(u8ExtData) { case SPI2_CMD_PIN: GPIO_ResetBits(GPIOB, GPIO_Pin_10);// PA10:D/C command = 0 break; default: GPIO_SetBits(GPIOB, GPIO_Pin_10);// PA10:D/C data = 1 break; } GPIO_ResetBits(GPIOB, GPIO_Pin_12); // PA12:Turn on NSS.--> Normal high, active low. SPI_I2S_SendData(SPI2, u8Data); // Send data u8Nss2Low = 1; } } } else { if(SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_BSY) == RESET) //If it's free to send data. { GPIO_SetBits(GPIOB, GPIO_Pin_12); u8Nss2Low = 0; } } //============================================================================== // Get data if(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == SET) //If there is data need to received. { u8Data = SPI_I2S_ReceiveData(SPI1); PUT(SPI1_RXBuffer, u8Data); } if(SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == SET) //If there is data need to received. { u8Data = SPI_I2S_ReceiveData(SPI2); PUT(SPI2_RXBuffer, u8Data); } }