Hi,
While debugging a code of mine that uses SPI to interface with a chip that requires data mode 3, I think I found a bug in the setDataMode function:
In 0021 it is :
void SPIClass::setDataMode(uint8_t mode)
{
SPCR = (SPCR & ~SPI_MODE_MASK) | mode;
}
When the 'mode' argument is in the range described in the documentation (0-3), it does change the SPI data mode(CPOL and CPHA), but the bits SPR0 and SPR1, meaning it overwrites the SPI clock rate.
I think it should be something like:
void SPIClass::setDataMode(uint8_t mode)
{
SPCR = (SPCR & ~SPI_MODE_MASK) | ( (mode & 0x02)?1:0 ) << CPOL ) | ( ( mode & 0x01) << CPHA );
}
or simply:
void SPIClass::setDataMode(uint8_t mode)
{
SPCR = (SPCR & ~SPI_MODE_MASK) | (mode << 2 );
}
Thanks for all your hard work guys!