Receiving Data Over Spi - Bosch XDK110 Getting Started

Cross-domain development kit
Hide thumbs Also See for XDK110:
Table of Contents

Advertisement

Extension Bus Advanced Guide | XDK110

4.4 Receiving data over SPI

Now that transmitting data over SPI was explained, receive data over SPI is explained in this section. For that, a function
SpiReadRegister()
called
Code 25. Read data from a sensor slave
void
SpiReadRegister(uint8_t
/* CS pin Set to Low */
SpiSetCSLow();
Retcode_T
recvReturn;
uint8_t
readData = 0xFF;
if
((readLength > 0) && (spiCompleteSync != NULL)){
recvReturn = MCU_SPI_Send(SpiHandle, &regAddr, readLength);
if
(recvReturn == RETCODE_OK){
xSemaphoreTake(spiCompleteSync, SPI_DATA_TRANSFER_TIMEOUT_MILLISEC);
}
recvReturn = MCU_SPI_Receive(SpiHandle, &readData, readLength);
if
(recvReturn == RETCODE_OK) {
xSemaphoreTake(spiCompleteSync, SPI_DATA_TRANSFER_TIMEOUT_MILLISEC);
*readVal = readData;
}
}
/* CS pin Set to High */
SpiSetCSHigh();
}
The function takes three parameters: a register address from where the data is read called
store the read data called
SpiSetCSLow()
function
to drive the chip select line to low to inform the slave device that a data transmission is initiated.
readData
First, the local variable
over SPI. Then, an if condition is used to check if the read length is greater than zero and if the
semaphore is not null. After that, the function
handle, the register address and the read length are used, to inform the slave device from which register a value should be
read.
Afterwards, the return value of this function call is evaluated. If the return value corresponds to
xSemaphoreTake()
function
not completed within 10ms - as specified by the macro
After sending is completed, either successfully or due to the timeout, the function
spiCompleteSync
semaphore
readData
variable
for storing the incoming data, and the read length.
Again, the return value is evaluated and if
spiCompleteSync
.
is implemented in the following outline.
regAddr,
uint8_t
readVal
, and the length of read data called
is declared and initialized. This variable will temporarily hold the incoming data received
MCU_SPI_Send()
spiCompleteSync
is called on
had been released by a TX complete event. This function receives the SPI handle, the local
RETCODE_OK
*readVal,
uint32_t
readLength
is called to initiate data transmission. As inputs, the SPI
to block the function until sending is completed. If sending is
SPI_DATA_TRANSFER_TIMEOUT_MILLISEC
xSemaphoreTake()
is returned,
readLength){
regAddr
, a pointer which will
. The function body itself calls the
spiCompleteSync
RETCODE_OK
- a timeout is issued.
MCU_SPI_Receive()
is called after the
is called on the semaphore
22 24
|
, then the

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents