spi_master_enable(0,0,896)
When I sent the command: SPI.setBitOrder(MSBFIRST); the the Debug output was:
Bit order set to 1
spi_master_enable(0,0,768)
The VS1003B (VS1053B), the Ethercard library, the ILI9341 LCD and the SSD1306 OLED use the MSBFIRST.
Do you think is a good idea to set the setBitOrder(MSBFIRST) as default into the SPI library during the SPI initialization <SPI.begin()> ?
Register SPCR, bit DORD = 0 = MSB
ATmega328p page 172
In that case we should probably change it to match the AVR (I’ve no idea why LeafLabs would have set the default to the other value)
The file is the Arduino_STM32\STM32F1\cores\maple\wirish_constants.h
I swapped the two lines in enum BitOrder . That makes default the MSBFIRST on SPI ports.
#ifndef _WIRING_CONSTANTS_
#define _WIRING_CONSTANTS_
#ifdef __cplusplus
extern "C"{
#endif
enum BitOrder {
//LSBFIRST = 0,
//MSBFIRST = 1
LSBFIRST = 1,
MSBFIRST = 0
};
#ifdef __cplusplus
}
#endif
#endif
I found a simple solution.
I will do some further tests on I2C
Where else do you think we will have problem on source code (libraries) ?
https://github.com/rogerclarkmelbourne/ … q=BitOrder
not so less files are using BitOrder….
I will do some more I2C devices tests.
https://github.com/rogerclarkmelbourne/ … q=BitOrder
not so less files are using BitOrder….
enum BitOrder {
LSBFIRST = 0,
MSBFIRST = 1
};
enum BitOrder {
LSBFIRST = 0,
MSBFIRST = 1
};
enum BitOrder {
LSBFIRST = 0,
MSBFIRST = 1
};
Edit.
I need to test this to make sure the SD lib still works etc,
But as far as I can see, we just need to initialise the bitorder in the constructor to MSBFIRST
e.g. add a line at the bottom of the constructor to set it. We may also want to explicitly set the clock divider and the mode, even though the initialised values may be OK already. It just makes it easier for anyone reading the code to work out what the default values are
(Scroll to the bottom of this code window)
SPIClass::SPIClass(uint32 spi_num) {
switch (spi_num) {
#if BOARD_NR_SPI >= 1
case 1:
this->spi_d = SPI1;
break;
#endif
#if BOARD_NR_SPI >= 2
case 2:
this->spi_d = SPI2;
break;
#endif
#if BOARD_NR_SPI >= 3
case 3:
this->spi_d = SPI3;
break;
#endif
default:
ASSERT(0);
}
bitOrder=MSBFIRST;
}
Thanks for testing.
I’ve not had time to test it yet.
I will wait for a bit more feedback, and if no one objects to the change, I will push the change a bit later…