| | |
| | | |
| | | |
| | | int writetospi_serial( uint16_t headerLength, |
| | | const uint8_t *headerBuffer, |
| | | uint32_t bodylength, |
| | | const uint8_t *bodyBuffer |
| | | ); |
| | | const uint8_t *headerBuffer, |
| | | uint32_t bodylength, |
| | | const uint8_t *bodyBuffer |
| | | ); |
| | | |
| | | int readfromspi_serial( uint16_t headerLength, |
| | | const uint8_t *headerBuffer, |
| | | uint32_t readlength, |
| | | uint8_t *readBuffer ); |
| | | const uint8_t *headerBuffer, |
| | | uint32_t readlength, |
| | | uint8_t *readBuffer ); |
| | | /*! ------------------------------------------------------------------------------------------------------------------ |
| | | * Function: openspi() |
| | | * |
| | |
| | | */ |
| | | int openspi(/*SPI_TypeDef* SPIx*/) |
| | | { |
| | | // done by port.c, default SPI used is SPI1 |
| | | // done by port.c, default SPI used is SPI1 |
| | | |
| | | return 0; |
| | | return 0; |
| | | |
| | | } // end openspi() |
| | | |
| | |
| | | */ |
| | | int closespi(void) |
| | | { |
| | | while (port_SPIx_busy_sending()); //wait for tx buffer to empty |
| | | while (port_SPIx_busy_sending()); //wait for tx buffer to empty |
| | | |
| | | port_SPIx_disable(); |
| | | port_SPIx_disable(); |
| | | |
| | | return 0; |
| | | return 0; |
| | | |
| | | } // end closespi() |
| | | |
| | |
| | | ) |
| | | { |
| | | |
| | | int i=0; |
| | | int i = 0; |
| | | |
| | | decaIrqStatus_t stat ; |
| | | |
| | |
| | | |
| | | SPIx_CS_GPIO->BRR = SPIx_CS; |
| | | |
| | | for(i=0; i<headerLength; i++) |
| | | for(i = 0; i < headerLength; i++) |
| | | { |
| | | SPIx->DR = headerBuffer[i]; |
| | | SPIx->DR = headerBuffer[i]; |
| | | |
| | | while ((SPIx->SR & SPI_I2S_FLAG_RXNE) == (uint16_t)RESET); |
| | | while ((SPIx->SR & SPI_I2S_FLAG_RXNE) == (uint16_t)RESET); |
| | | |
| | | SPIx->DR ; |
| | | SPIx->DR ; |
| | | } |
| | | |
| | | for(i=0; i<bodylength; i++) |
| | | for(i = 0; i < bodylength; i++) |
| | | { |
| | | SPIx->DR = bodyBuffer[i]; |
| | | SPIx->DR = bodyBuffer[i]; |
| | | |
| | | while((SPIx->SR & SPI_I2S_FLAG_RXNE) == (uint16_t)RESET); |
| | | while((SPIx->SR & SPI_I2S_FLAG_RXNE) == (uint16_t)RESET); |
| | | |
| | | SPIx->DR ; |
| | | } |
| | | SPIx->DR ; |
| | | } |
| | | |
| | | SPIx_CS_GPIO->BSRR = SPIx_CS; |
| | | |
| | |
| | | ) |
| | | { |
| | | |
| | | int i=0; |
| | | int i = 0; |
| | | |
| | | decaIrqStatus_t stat ; |
| | | |
| | |
| | | |
| | | SPIx_CS_GPIO->BRR = SPIx_CS; |
| | | |
| | | for(i=0; i<headerLength; i++) |
| | | for(i = 0; i < headerLength; i++) |
| | | { |
| | | SPIx->DR = headerBuffer[i]; |
| | | SPIx->DR = headerBuffer[i]; |
| | | |
| | | while((SPIx->SR & SPI_I2S_FLAG_RXNE) == (uint16_t)RESET); |
| | | while((SPIx->SR & SPI_I2S_FLAG_RXNE) == (uint16_t)RESET); |
| | | |
| | | readBuffer[0] = SPIx->DR ; // Dummy read as we write the header |
| | | readBuffer[0] = SPIx->DR ; // Dummy read as we write the header |
| | | } |
| | | |
| | | for(i=0; i<readlength; i++) |
| | | for(i = 0; i < readlength; i++) |
| | | { |
| | | SPIx->DR = 0; // Dummy write as we read the message body |
| | | SPIx->DR = 0; // Dummy write as we read the message body |
| | | |
| | | while((SPIx->SR & SPI_I2S_FLAG_RXNE) == (uint16_t)RESET); |
| | | |
| | | readBuffer[i] = SPIx->DR ;//port_SPIx_receive_data(); //this clears RXNE bit |
| | | while((SPIx->SR & SPI_I2S_FLAG_RXNE) == (uint16_t)RESET); |
| | | |
| | | readBuffer[i] = SPIx->DR ;//port_SPIx_receive_data(); //this clears RXNE bit |
| | | } |
| | | |
| | | SPIx_CS_GPIO->BSRR = SPIx_CS; |