Reading 1 byte only in SPI half duplex
Hi everyone,
I'm using a P-NUCLEO-WB55 for an SPI application with a CMT2219A (HF receiver) which works in Half duplex.
I try to read its configuration registers by sending the address with the R/W bit set, then reading the bus by clocking during a byte (see the following picture:)
The problem is that when reading, the MCU is clocking during 2 bytes instead of 1 as you can see:
If I try to read 2 bytes, then the MCU is clocking during 3 bytes and so on...
Actually, the values read on the picture are correct, but we're loosing time reading an extra byte each time (and this is not clean even if this doesn't affect the integrity of the data).
Here is the SPI's configuration:
void SPI_CMT2219A_Init(void)
{
hspi1.Instance = SPI1;
hspi1.Init.Mode = SPI_MODE_MASTER;
hspi1.Init.Direction = SPI_DIRECTION_1LINE;
hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi1.Init.NSS = SPI_NSS_SOFT;
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_256;
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi1.Init.CRCLength = 0; // hspi1.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
// hspi1.Init.CRCPolynomial = 7;
hspi1.Init.NSSPMode = SPI_NSS_PULSE_DISABLED;
if (HAL_SPI_Init(&hspi1) != HAL_OK)
{
Error_Handler();
}
}And here's the function that produces this result:
void SPI_CMT2219A_read_config(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size)
{
HAL_StatusTypeDef err = HAL_OK;
uint8_t addr = 0;
for (uint8_t i = 0; i < Size; i++)
{
addr = i | 0x80;
HAL_GPIO_WritePin(CSB_CMT2219A_PORT, CSB_CMT2219A_PIN, GPIO_PIN_RESET); // Toggle CSB
err = HAL_SPI_Transmit(hspi, &addr, 1, 1);
if (HAL_OK != err)
asm("nop");
err = HAL_SPI_Receive(hspi, pData + i, 1, 1);
if (HAL_OK != err)
asm("nop");
HAL_GPIO_WritePin(CSB_CMT2219A_PORT, CSB_CMT2219A_PIN, GPIO_PIN_SET); // Reset CSB
}
}I want to read the 62 configuration bytes for test purposes and finding a solution to this problem could lead to the solution to the fifo-reading issue I'm facing too.
As you probably guessed, I'm using the HAL library from CubeIDE.
Thanks in advance for your help!