hi,
there is an important difference between Arduino Atmel controllers and ARM controllers:
When porting a software using SPI interface for a SD card from Mega2560 to Teensy3.2 the transfer of data on Teensy with 96 MHz was much slowlier than on Mega2560 with 16 MHz.
The reason is that the SPCR register of Teensy (MK20DX256) cannot be read, it is only writeable.
The initial software to configure the SPI interface:
At first the SPCR register is set to 0x53 which defines a very low clock frequency for the SPI interface.
After some initialization steps the function SD_L0_SpiSetHighSpeed(void) is called which shall increase the clock frequency.
On the Teensy3.2 the SPCR register had the same value after calling SD_L0_SpiSetHighSpeed() as before. The value of SPSR was changed according to the code. Therefore the SPI interface was running with quite a low freqency.
Saving the content of SPCR to a global variable, changing its value there and then writing it to the register solved the problem.
there is an important difference between Arduino Atmel controllers and ARM controllers:
When porting a software using SPI interface for a SD card from Mega2560 to Teensy3.2 the transfer of data on Teensy with 96 MHz was much slowlier than on Mega2560 with 16 MHz.
The reason is that the SPCR register of Teensy (MK20DX256) cannot be read, it is only writeable.
The initial software to configure the SPI interface:
Code:
SPCR = (0 << SPIE) | /* SPI Interrupt Enable */
(1 << SPE) | /* SPI Enable */
(0 << DORD) | /* Data Order: MSB first */
(1 << MSTR) | /* Master mode */
(0 << CPOL) | /* Clock Polarity: SCK low when idle */
(0 << CPHA) | /* Clock Phase: sample on rising SCK edge */
(1 << SPR1) | /* Clock Frequency: f_OSC / 128 */
(1 << SPR0);
SPSR &= ~(1 << SPI2X); /* No doubled clock frequency */
...
void SD_L0_SpiSetHighSpeed(void)
{
SPCR &= ~((1 << SPR1) | (1 << SPR0)); /* Clock Frequency: f_OSC / 4 */;
SPSR |= (1 << SPI2X); /* Doubled Clock Frequency: f_OSC / 2 */
}
After some initialization steps the function SD_L0_SpiSetHighSpeed(void) is called which shall increase the clock frequency.
On the Teensy3.2 the SPCR register had the same value after calling SD_L0_SpiSetHighSpeed() as before. The value of SPSR was changed according to the code. Therefore the SPI interface was running with quite a low freqency.
Saving the content of SPCR to a global variable, changing its value there and then writing it to the register solved the problem.