Hi, Already I'm too working with SPI.
yesterday I programmed SPI hard with SD card.
[code:1:3dd6d57e1a]' SPI declaration:
Config Portb.0 = Output ' The !SS pin can only be used as an output in SPI hardware master mode)
Sd_cs Alias Portb.0
Config Portb.2 = Output
Sd_di Alias Portb.2 ' MOSI
Config Portb.1 = Output
Sd_clk Alias Portb.1 ' Clock
Config Portb.3 = Input
Sd_do Alias Portb.3 ' MISO
' HW SPI - make sure that your initial clock frequency <= 400 kHz
' After initialization, try to increase the speed and also set the SPCR register to double speed
Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = Low , Phase = 0 , Clockrate = 64 , Noss = 1 , Spiin = 255[/code:1:3dd6d57e1a]
This is a part of KokkeKat FAT-free SD card library.
This is work fine, but i have hardware pins occuped, then i go to software SPI.
At the begginning I have problem with pins declaration. But a few attempts and I solve this.
[code:1:3dd6d57e1a]' SPI declaration:
Config Portf.7 = Output ' The !SS pin can only be used as an output in SPI hardware master mode)
Sd_cs Alias Portf.7
Config Portf.5 = Output
Sd_di Alias Portf.5 ' MOSI
Config Portf.6 = Output
Sd_clk Alias Portf.6 ' Clock
Config Portf.4 = Input
Sd_do Alias Portf.4 ' MISO
' HW SPI - make sure that your initial clock frequency <= 400 kHz
' After initialization, try to increase the speed and also set the SPCR register to double speed
Config Spi = Soft , Din = Pinf.4 , Dout = Portf.5 , Clock = Portf.6 , Ss = Portf.7 , Spiin = 255 , Mode = 0 ', Speed = 1[/code:1:3dd6d57e1a]
I have M128 and this pins is a JTAG. very important is uncheck JTAG in FUSES.
Impotrant is also set mode to 0. The default is 1.
If you have lower speed crystal, try with speed=1 or higher.
↧