2021-07-31 03:49 AM
2021-07-31 04:02 AM
I am using SPI function in Nucleo F411RE.
I use PicoScope to capture SPI signals as showed below:The bottom line is Chip Select (CS). How come there is some random spike when it is supposed be kept low.
My code is showed in the following lines:
void spiWrite() {
// Write 3 bytes starting at given address
char spi_buf[6];
// write to register 0x03
spi_buf[0] = 0x03; // register address
spi_buf[1] = 0x0A;
spi_buf[2] = 0x84;
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_RESET);
HAL_SPI_Transmit(&hspi1, (uint8_t *)spi_buf, 3, 100);
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_SET);
delay_us(5);
}
HAL_SPI_Transmit(&hspi1, (uint8_t *)spi_buf, 3, 100);
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_SET);
delay_us(5);
}
2021-07-31 06:31 AM
Probably poor grounding/return.
Also you can try to decrease the SCK/MOSI slew rate/GPIO drive (GPIO_OSPEEDR setting).
JW
2021-07-31 07:41 AM
I only connect SPI pins to PicoScope pins, I didn't forget to connect GND pin. No slave connection yet.
Where to set GPIO_OSPEEDR setting?
2021-07-31 08:08 AM
BTW, I tested a case where spi_transmit is not called. I just toggle the CS pin in fast speed (us gap). There is no spike.
2021-07-31 08:46 AM
> I just toggle the CS pin
I see above more signals to change at the same time. Try toggling more pins at once.
> in fast speed (us gap).
As I've said, the slew rate of the signals edge is what matters here, not pulse length.
> Where to set GPIO_OSPEEDR setting?
I don't know, this is your program. I don't use Cube. Probably where other attributes of given pin are set.
JW
2021-08-01 03:17 AM
You are right. Just now I double-checked my wiring. GND pin is wrongly connected.
Thx