cancel
Showing results for 
Search instead for 
Did you mean: 

Transmitting multiple bytes through SPI

ACan.1
Associate II

Hi everyone,

I am trying to transmit multiple bytes via SPI.

I could read the data through spi, so connections should be ok.

Does anyone have idea what can be the reason, that I can not write data to the register of the slave?

int writetospi(uint16 headerLength, const uint8 *headerBuffer, uint32 bodyLength, const uint8 *bodyBuffer)
{
	while (HAL_SPI_GetState(&hspi2) != HAL_SPI_STATE_READY);
 
    HAL_GPIO_WritePin(DW_SPI_Port, DW_SPI_Pin, GPIO_PIN_SET); /**< Put chip select line high */
    HAL_GPIO_WritePin(DW_SPI_Port, DW_SPI_Pin2, GPIO_PIN_SET); /**< Put chip select line high */
 
    HAL_GPIO_WritePin(DW_SPI_Port, DW_SPI_Pin, GPIO_PIN_RESET); /**< Put chip select line low */
    HAL_GPIO_WritePin(DW_SPI_Port, DW_SPI_Pin2, GPIO_PIN_RESET); /**< Put chip select line low */
 
    HAL_SPI_Transmit(&hspi2, (uint8_t *)&headerBuffer[0], headerLength, 300);	/* Send header in polling mode */
    HAL_SPI_Transmit(&hspi2, (uint8_t *)&bodyBuffer[0], bodyLength, 300);		/* Send data in polling mode */
 
    HAL_GPIO_WritePin(DW_SPI_Port, DW_SPI_Pin, GPIO_PIN_SET); /**< Put chip select line high */
    HAL_GPIO_WritePin(DW_SPI_Port, DW_SPI_Pin2, GPIO_PIN_SET); /**< Put chip select line high */
 
    return 0;
} // end writetospi()

Note: Wrong pin was connected on the hardware as chip select, therefore I used both, chip select pin as well as connected pin.

This is a device of Decawave, I need to write this function so all the apis of manufacturer works. Thank you.

Best regards

3 REPLIES 3
Jack Liu
Associate

I think you can try to understand this question form three points.First, you can write register config, then read them. Second, you can watch program running when debug.If the second data can't be written by spi, your program is wrong.Third, I can't understand that "Wrong pin was connected on the hardware as chip select, therefore I used both, chip select pin as well as connected pin." SPI can run by hardware or software. Best glad!��

ACan.1
Associate II

Thank you for your answer Jack,

I am trying to write a register and read from it. I tried to write single byte, it did not work too. Is hal_spi_transmit() used correctly? Is parameter wrong or can it be used in serie, one hal_spi_transmit after another?

(About pins, I just wanted to share completely and write description so it wont confuse anyone. It is just chip select pin.)

ACan.1
Associate II

Does anyone know, is the usage of HAL_SPI_Transmit(...) correct? Can we use it twice after each other?