2023-01-26 10:09 AM
Hi everyone,
A new issue has occur and have no idea as to why the transmission would be sometimes corrupt. I try sending the word "Hello World" as a test, however sometimes I would receieve the word but sometimes I would receivbe garage values that various in size.
The setup:
void initSPI() {
LL_AHB4_GRP1_EnableClock(LL_AHB4_GRP1_PERIPH_GPIOB);
LL_AHB4_GRP1_EnableClock(LL_AHB4_GRP1_PERIPH_GPIOA);
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_SPI2);
//LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SPI1);
LL_GPIO_InitTypeDef LL_GPIO;
LL_SPI_InitTypeDef LL_SPI;
LL_GPIO_StructInit(&LL_GPIO);
LL_SPI_StructInit(&LL_SPI);
// Setting up SPI 1 GPIO
LL_GPIO.Alternate = LL_GPIO_AF_5;
LL_GPIO.Mode = LL_GPIO_MODE_ALTERNATE;
LL_GPIO.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
LL_GPIO.Pin = LL_GPIO_PIN_13 | LL_GPIO_PIN_14 | LL_GPIO_PIN_15;
LL_GPIO.Pull = LL_GPIO_PULL_DOWN;
LL_GPIO.Speed = LL_GPIO_SPEED_HIGH;
LL_GPIO_Init(GPIOB, &LL_GPIO);
LL_GPIO_StructInit(&LL_GPIO);
// Setting up SPI 1 GPIO
LL_GPIO.Alternate = 0x00;
LL_GPIO.Mode = LL_GPIO_MODE_OUTPUT;
LL_GPIO.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
LL_GPIO.Pin = LL_GPIO_PIN_4;
LL_GPIO.Pull = LL_GPIO_PULL_DOWN;
LL_GPIO.Speed = LL_GPIO_SPEED_HIGH;
LL_GPIO_Init(GPIOA, &LL_GPIO);
// Setting up SP1 1 Peri
LL_SPI.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV256;
LL_SPI.BitOrder = LL_SPI_MSB_FIRST;
LL_SPI.CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE;
LL_SPI.CRCPoly = 0x00;
LL_SPI.ClockPhase = LL_SPI_PHASE_1EDGE;
LL_SPI.ClockPolarity = LL_SPI_POLARITY_LOW;
LL_SPI.DataWidth = LL_SPI_DATAWIDTH_8BIT;
LL_SPI.Mode = LL_SPI_MODE_MASTER;
LL_SPI.NSS = LL_SPI_NSS_SOFT;
LL_SPI.TransferDirection = LL_SPI_FULL_DUPLEX;
LL_SPI_Init(SPI2, &LL_SPI);
//LL_SPI_EnableGPIOControl(SPI2);
}
The usuage:
int main(void)
{
char* word = "Hello World";
HAL_Init();
SystemClock_Config();
initSPI();
LL_SPI_SetTransferSize(SPI2, 11);
GPIOA->BSRR |= (1 << 4);
LL_SPI_Enable(SPI2);
LL_SPI_StartMasterTransfer(SPI2);
GPIOA->BSRR |= (1 << 20);
for (int i = 0; i < 11; i++) {
while(LL_SPI_IsActiveFlag_TXP(SPI2) == 0){};
LL_SPI_TransmitData8(SPI2, word[i]);
}
while(LL_SPI_IsActiveFlag_TXP(SPI2) == 0){};
while(LL_SPI_IsActiveFlag_EOT(SPI2) == 0){};
LL_SPI_Disable(SPI2);
GPIOA->BSRR |= (1 << 4);
while (1)
{
}
}
The problem: