C3 SPI Mode

Before going on in developing our SPI driverwe must take in consideration the device we are going to communicate with. Every device has its own SPI mode of operation. This is only the way you can send/receive data according to the clock signal.

There are 4 combination of way of sending data accodring to the state of the clock signal and the phase of it.

Usually the most common used mode is "0" by which you can read data on the rising edge of the clock and write on the falling edge of the clock.

So a sugggestion is to always check the datasheet of the device you are going to use and understand the way it can communicate to the master device.

Last code published has been "translated" from official driver, it works with SRAM, but not with SD card. So if you check both device mode you will be sure on what you are doing.

So with  mode 0 you can use this flow:

1) prepare data out on outa port
2) raise clock
3) read data in from ina port
4) drop clock.

If you need to use both SD card and SRAM this will work. In my case I will need to read a game rom and store it on SRAM first bank. So communication must switch between SPI channels and must be the same kind.