' Pin configuration and SPI interface
symbol SD_CS_PIN = C. 2' Pin CS (Chip Select) SD Card
symbol MOSI_PIN = C. 0 ' PIN MOSI (Master Out Slave In)
MISO_PIN symbol = C. 7' PIN MISO (Master In Slave Out)
symbol SCK_PIN = C. 5' Pin SCK (serial clock)
results from the given m8
' Configure pins for SD cards
high SD_CS_PIN 'setting the CS pin to high state (SD card inactive)
serout SCK_PIN, N2400_8, ($FF) ' Sending byte to use SPI interface
' Function to initialize SD cards
initSD:
low SD_CS_PIN' SD card activation
serout SCK_PIN, N2400_8, (40$, 0, 0, 0, 0, 0, 0, 95$) ' Initialization Command
pause 100' Wait for initialization
High SD_CS_PIN' SD Card Deactivation
back
gosub initSD
Function of extra text to file on SD demand
save to SD:
low SD_CS_PIN' SD card activation
serout SCK_PIN, N2400_8, ($41, 0, 0, 0, 0, $95) ' Write command
Pause 100' Wait for SD cards to be ready
serout SCK_PIN, N2400_8, ("Hello, World!") ' Sample text to write
High SD_CS_PIN' Deactivate SD Cards
back
gosub save to SD
Main Program
Main:
call initSD ' Initialize SD cards
' Here you get the code that was uploaded before saving the file
saveToSD ' Save to description SD