Runt Pulse Issue on SPI MOSI
Hello,
I'm trying to do a basic spi master transmit, and am having issues with the MOSI pin output. It seems the value is getting written, but the voltage swing is ~200mV rather than full value. I suspect I have the GPIO pin mis-configured, but I'm at a loss as to where my mistake is after reading the datasheet and searching online. Here's my basic code for stm32l476 (using the nucleo board)...
void basic_spi() {
GPIO_TypeDef* gpio = GPIOA;
SPI_TypeDef* spi = SPI1;
uint8_t data = 0x12;
// gpio config
RCC->AHB2ENR |= (1<<0);
GPIOA->MODER &= ~((3<<10)|(3<<12)|(3<<14)|(3<<18));
//af pa5,pa6,pa7,output pa9
GPIOA->MODER |= (2<<10)|(2<<12)|(2<<14)|(1<<18);
// high speed
GPIOA->OSPEEDR |= (3<<10)|(3<<12)|(3<<14)|(3<<18);
// af5 for pa5,pa6,pa7
GPIOA->AFR[0] |= (5<<20)|(5<<24)|(5<<28);
// spi config
RCC->APB2ENR |= (1<<12); //clock enable
SPI1->CR1 &= ~(SPI_CR1_RXONLY | SPI_CR1_LSBFIRST | SPI_CR1_BR);
SPI1->CR1 |= (SPI_CR1_CPOL | SPI_CR1_CPHA | SPI_CR1_SSM | SPI_CR1_SSI |SPI_CR1_BR_0 | SPI_CR1_BR_1 | SPI_CR1_MSTR);
SPI1->CR2 = 0;
// spi enable
SPI1->CR1 |= (1<<6);
while (1) {
GPIOA->BSRR |= (1<<9)<<16;
while (!((SPI1->SR)&(1<<1))) {};
*(volatile uint8_t*)&SPI1->DR = (uint8_t) data;
while (!((SPI1->SR)&(1<<1))) {};
while (((SPI1->SR)&(1<<7))) {};
GPIOA->BSRR |= (1<<9);
for (uint32_t i = 0; i < 100000; i++)
{
__NOP();
}
}
}
CH1 - CS (PA9)
CH2 - SCK (PA5)
CH3 - MISO (PA6) - not connected to any other device
CH4 - MOSI (PA7)
I'd appreciate any help you have, thanks!
