我有一个外围设备,我正在使用 Raspberry Pi 和
STM32G0B1(两种不同的设备,两种不同的设置)进行
通信
我基本上是在尝试重现我们在 STM32 平台上对这个外围设备所做的成功通信。我有一些奇怪的结果。
CS 线似乎变低或变高,过早/过晚导致读取不应该存在的位。
我正在发送 3 个单独的帧。4字节,10字节,1字节。没有正在读取的输入,因此可以忽略这些行。
下面我展示了 RPi 和 STM32 之间的输出比较。
下图显示了以下信号:
SDO
SDI <-- no traffic on any signal
CS
CLK
4 bytes frame on Rpi, matches code:
4 bytes on STM32 (should match above):
It can be seen that it appears the bits are shifted 1 to the left here.
The 10 byte frame:
Same again with the STM32:
The final frame is a single byte, the number '8'
On the Rpi it looks like this:
The STM32 reads this as 11
Here it looks like the CS line line stay low for too long causing a 1 to be read, where in the RPI it can be seen that CS goes high right at the end of the last byte.
My code uses the HAL libraries and the sending func
tion is simple:
- void spi_transfer(uint8_t board, uint8_t *pData, uint16_t Size) {
- HAL_StatusTypeDef status;
- HAL_GPIO_WritePin(SPI_CE0_GPIO_Port, SPI_CE0_Pin, GPIO_PIN_RESET);
- status = HAL_SPI_Transmit(&hspi1, pData, Size, 100);
- HAL_GPIO_WritePin(SPI_CE0_GPIO_Port, SPI_CE0_Pin, GPIO_PIN_SET);
- if (status != HAL_OK) {
- serprintf("Error writing to SPI on board: %i. (%i)
", board, status); - }
- }
I've experimented with the clock speed, and some other settings. But nothing seemed to help.
- 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_LOW;
- hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
- hspi1.Init.NSS = SPI_NSS_SOFT;
- hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16;
- 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_DISABLE;
Thanks for any tips