2016-03-10 02:19 AM
I am using a custom made STM32F302RE board.
I have configured my SPI as follows:hspi2.Instance = SPI2;
hspi2.Init.Mode = SPI_MODE_MASTER;
hspi2.Init.Direction = SPI_DIRECTION_2LINES;
hspi2.Init.DataSize = SPI_DATASIZE_8BIT;
hspi2.Init.CLKPolarity = SPI_POLARITY_HIGH;
hspi2.Init.CLKPhase = SPI_PHASE_2EDGE;
hspi2.Init.NSS = SPI_NSS_HARD_OUTPUT;
hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
//hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4;
hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi2.Init.TIMode = SPI_TIMODE_DISABLED;
hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
hspi2.Init.NSSPMode = SPI_NSS_PULSE_DISABLED;
HAL_SPI_Init(&hspi2);
I want to send a message using SPI. As I am sending a data that is several bytes long, I wrote it like this:
static void WriteCommand(
const unsigned char *pucBuffer,
unsigned long ulCount)
{
SPI_HandleTypeDef hspi2;
// Return if SSI port is not ready.
if (hspi2.State != HAL_SPI_STATE_READY)
{
return;
}
// Wait until the SSI is not busy, meaning that all previous data has
// been transmitted.
while (hspi2.State == HAL_SPI_STATE_BUSY)
{
}
// Clear the command/control bit to enable command mode.
HAL_GPIO_WritePin (DISPLAY_CTRL_PORT, DISPLAY_DC_PIN, GPIO_PIN_RESET);
// Loop while there are more bytes left to be transferred.
while( ulCount != 0 )
{
hspi2.Instance = SPI2;
hspi2.TxXferCount = ulCount;
hspi2.pTxBuffPtr = (uint8_t *)&pucBuffer;
// Write the next byte to the controller.
HAL_SPI_Transmit (&hspi2, (uint8_t *)&pucBuffer, ulCount, SPI_DEFAULT_TIMEOUT);
*pucBuffer++;
// Decrement the BYTE counter.
ulCount--;
}
hspi2.State = HAL_SPI_STATE_READY;
}
*pucBuffer represents the tx buffer and ulcount represents number of bytes.
However, I am not able to transmit the data successfully.
Any suggestions??
2023-09-12 08:10 AM
How is your chip select wired? Have you seen the signals on an oscilloscope ?