2017-03-30 07:56 PM
Hi All,
I am new to STM , I have problem in read and write data simultaneously using STM32L476 board. i just created a new project using STMcubeMX and try to read and write simultaneously using HAL_SPI_TransmitReceive_IT , and when i checked on my spi sniffer, spi data is sent byte ,byte ... Here my spi init config
hspi1.Instance = SPI1;
hspi1.Init.Mode = SPI_MODE_MASTER; hspi1.Init.Direction = SPI_DIRECTION_2LINES; hspi1.Init.DataSize = SPI_DATASIZE_8BIT; hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH; 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.CRCPolynomial = 7; hspi1.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE; hspi1.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;if (HAL_SPI_Init(&hspi1) != HAL_OK)
is any missing in my configuration.
Thanks in advance.
2017-03-31 02:30 AM
Hi
sudi.sampath
,
Welcome to STM32 community
As novice user of STM32 product,I'd highly recommend you to start with ready example under the STM32L4 cube firmware package:
STM32Cube_FW_L4_V1.7.0\Projects\STM32L476RG-Nucleo\Examples\SPI
-Nesrine-
2017-03-31 02:31 PM
Thanks Nesrine,
it tried to modify example programming still i see the same issue, all spi message are sent in 1 byte format
for instace :- i am trying to send 3 bytes (0x12 0x34 0x56 ) , but i see data is sent 0x12 , 0x34 and 0x56 are transmitted in 3 different spi data.
2017-04-01 11:03 PM
I use these functions after HAL initialisation:
void quickSend8SPI(SPI_HandleTypeDef *hspi){
while( !( hspi->Instance->SR & SPI_FLAG_TXE));
*((__IO uint8_t *)&hspi->Instance->DR) = TxSPIByte; }void quickSendReceive8SPI(SPI_HandleTypeDef *hspi){while( !( hspi->Instance->SR & SPI_FLAG_TXE));
*((__IO uint8_t *)&hspi->Instance->DR) = TxSPIByte; // force the SPI to transceive 8 bit while( !( hspi->Instance->SR & SPI_FLAG_TXE)); while( ( hspi->Instance->SR & SPI_FLAG_BSY)); while( ( hspi->Instance->SR & SPI_FLAG_RXNE)) RxSPIByte1 = hspi->Instance->DR;
}
2017-04-05 07:05 PM
still no luck.
i tried below steps
HAL_GPIO_WritePin((GPIO_TypeDef *)GPIO_AF5_SPI1,GPIO_PIN_4,GPIO_PIN_RESET);
status = HAL_SPI_TransmitReceive_IT(spiHandle,(uint8_t *)txBuff,(uint8_t *)rxBuff,Size); while( spiHandle->State == HAL_SPI_STATE_BUSY ); HAL_GPIO_WritePin((GPIO_TypeDef *)GPIO_AF5_SPI1,GPIO_PIN_4,GPIO_PIN_SET);still i see byte byte transmission.
2017-04-06 07:52 AM
Could the problem be:
hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
2017-04-06 10:24 AM
hspi1.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
turn off hardware nss and toggle the chip select pin manually
2017-04-06 10:24 AM
Is the requesr here not to have clock delays between bytes?
Try to blindly write 3 bytes first, this might feed the hungry fifo, or write 16 bit which will be sliced as 2x8 bit by the spi if in 8 bit transmit mode...
2017-04-06 11:25 AM
how do enable packing mode for spi transfer
2017-04-06 11:34 AM
Can you fill us in on why it matters? The clock doesn't change between the bytes, so the delay just comes down to a delay of about 700 nanoseconds. Are you that strapped for time?
Andrei
(
)