2021-08-31 12:36 PM
/* USER CODE BEGIN 2 */
// CS pin should befault high
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_SET);
uint8_t TX_Data[13] = "Hello World!";
uint8_t RX_Data[13];
/* USER CODE END 2 */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_RESET); // CS set LOW
HAL_SPI_TransmitReceive(&hspi2, TX_Data, RX_Data, 13, 100);
}
while (hspi2.State == HAL_SPI_STATE_BUSY);
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_SET); // CS set HIGH
HAL_Delay(1000);
}
/* USER CODE END 3 */
}
Very simple code, but I do something wrong! I'm sending "Hello world" and in a logic analyzer I get a trash! Could you help me? link to my full main.c https://pastebin.com/jygZ5Rh1
Solved! Go to Solution.
2021-08-31 02:21 PM
Looks like your data is being sent MSB first, but being interpreted LSB first. Perhaps an error in the analyzer software somewhere. Try switching it to LSB first to see what happens.
0b01100101 = 0x65 = "e"
Reversed: 0b10100110 = 0xA6, which is what it's reporting.
2021-08-31 01:48 PM
You need to match the CPOL/CPHA values in your analyzer to what your code is doing. Signal looks correct.
2021-08-31 02:06 PM
Thanks for the answer! There are not many possibility! I tried all possible options with CPOL/CPHA and not only with CPOL/CPHA. The best option with that settings. But the problem still the same.
2021-08-31 02:21 PM
Looks like your data is being sent MSB first, but being interpreted LSB first. Perhaps an error in the analyzer software somewhere. Try switching it to LSB first to see what happens.
0b01100101 = 0x65 = "e"
Reversed: 0b10100110 = 0xA6, which is what it's reporting.
2021-08-31 11:13 PM
Thanks for the help! I do not know why, but now it works! I can only assume, after switching from "Least Significant Bit First" to "Least Significant Bit First" and ba�?k it start works!
2021-08-31 11:18 PM