Thanks for this great source of info. I've been reading your code to learn about programming the SAMD21.
I found a potential issue in the SPI code: when calling spi_ss(1) at the end of a transmission, you need to make sure that the transmit buffer is empty before unselecting the slave to avoid losing the last character with some slaves.
I would rewrite spi_ss as follows:
void spi_ss(int state)
{
if (state)
{
while (SPI_SERCOM.INTFLAG.bit.TXC==0); // Wait for transmit to finish
SPI_SERCOM->SPI.INTFLAG.bit.TXC = 1; // clear Int flag
HAL_GPIO_SS_write(1);
}
else
{
HAL_GPIO_SS_write(0);
}
}
In my case, I broke down this call in two functions: spi_begin() and spi_end(), following the same idea.
Thanks for this great source of info. I've been reading your code to learn about programming the SAMD21.
I found a potential issue in the SPI code: when calling
spi_ss(1)at the end of a transmission, you need to make sure that the transmit buffer is empty before unselecting the slave to avoid losing the last character with some slaves.I would rewrite spi_ss as follows:
In my case, I broke down this call in two functions: spi_begin() and spi_end(), following the same idea.