Transmitting 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.3 Transmitting data over SPI

Now that all configuration and initialization is done, data can be transmitted via SPI as outlined in Code 11. For that, a
function is implement, which can work with sensors or other slave devices attached to the Extension Bus.
Code 23. Write data to a sensor slave over SPI
void
SpiWriteRegister(uint8_t
Retcode_T
sendReturn;
SpiSetCSLow();
if
((writeLength > 0) && (spiCompleteSync != NULL)){
       sendReturn = MCU_SPI_Send(SpiHandle, &regAddr, writeLength);
if(sendReturn == RETCODE_OK){
xSemaphoreTake(spiCompleteSync, UINT32_C(0));
}
sendReturn = MCU_SPI_Send(SpiHandle, writeVal, writeLength);
if(sendReturn == RETCODE_OK){
xSemaphoreTake(spiCompleteSync, UINT32_C(0));
}
SpiSetCSHigh();
}
The function outlined in Code 23 takes three parameters, a register address called
containing the data to be transmitted called
The body of the function defines first a variable of the type
MCU_SPI_Send()
the function
set the voltage level of the chip select line to low. This informs the connected slave device that the master is about to send
or read data to or from it. Afterwards, an if condition is used to check if the length of the transmit data is is greater than zero
spiCompleteSync
and if the
Then the register address itself and its length is send via the function
SPI_T
the type
containing all information regarding the SPI interface, the send byte or buffer, and its length as parameters.
Please note: since only one byte is send in both write attempts, the write length is identically.
Afterwards, the return value of the function
xSemaphoreTake()
is called using the
In this case here, the parameter given to the function is zero to indicate that no timeout is used.
By taking the semaphore, it is ensured that no previous transmission over SPI is still processed because the semaphore
would not be available if that would be the case. The semaphore is then release by the implemented event for
event.TxComplete
in the function
Afterwards, the chip select line is raised to a high voltage level by using the function
Code 22.
SpiWriteRegister()
A call of the function
regAddr,
uint8_t
writeVal
, and the length of the data buffer called
. Afterwards, the function
semaphore is not null.
SPI_MCU_Send()
spiCompleteSync
SpiAppCallback()
could then be used, as shown in Code 24.
*writeVal,
uint32_t
Retcode_T
, this variable will be used to store the return value of
SpiSetCSLow()
, which was implemented in Code 21, is called to
SPI_MCU_Send()
is evaluated. If the evaluation is okay, then the function
semaphore with a second parameter, which is used as timeout.
. Then the procedure is done once more to send the write value.
writeLength){
regAddr
, a pointer to the buffer
writeLength
.
. The function takes a handle from
SpiSetCSHigh()
, implemented in
20 24
|

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents