Prop. C3 and fsrw.spin
prs09210
Posts: 2
Hello all,
I am new to the Spin language and the C3 development board and I am now running into my first problems. I have a formal education in C programming / assembly programming for Freescale micro controllers (B.E. Electromechanical Engineering) and a solid background with the Arduino tool, but I am pulling my hair out with frustration every step I take with this hardware / IDE. I am experimenting with SD card interfacing and I can't even get started. I tried using the c3_sd_drv_010.spin object, but it appears that the function for writing to a sector doesn't work (or the demo is broken). I read in my book "programming and customizing the mulitcore..." and learned about fsrw.spin. I wanted to use this instead because I have a book that verifies that it actually works for data logging, but it won't work with the C3 because of the multiplexed SPI bus. I read in the manual for the C3 and found an ?object? for asserting the chip select line for the SPI bus:
Here is the code I have been trying to get going with no luck:
I would greatly appreciate some help from an experienced C3 user. I could normally just bug one of my friends with micro controller questions, but I don't know anyone that uses propellers.
Please help!
I am new to the Spin language and the C3 development board and I am now running into my first problems. I have a formal education in C programming / assembly programming for Freescale micro controllers (B.E. Electromechanical Engineering) and a solid background with the Arduino tool, but I am pulling my hair out with frustration every step I take with this hardware / IDE. I am experimenting with SD card interfacing and I can't even get started. I tried using the c3_sd_drv_010.spin object, but it appears that the function for writing to a sector doesn't work (or the demo is broken). I read in my book "programming and customizing the mulitcore..." and learned about fsrw.spin. I wanted to use this instead because I have a book that verifies that it actually works for data logging, but it won't work with the C3 because of the multiplexed SPI bus. I read in the manual for the C3 and found an ?object? for asserting the chip select line for the SPI bus:
PUB SPI_Select_Channel( channel ) {{ This function sets the active SPI channel chip select on the SPI mux, this is accomplished by first resetting the SPI counter that feeds the SPI select decoder, then up counting the requested number of channels. PARMS: channel : channel 0 to 7 to enable where the channels are defined as follows 0 - NULL channel, disables all on/off board devices. 1 - 32K SRAM Bank 0. 2 - 32K SRAM Bank 1. 3 - 1MB FLASH Memory. 4 - MCP3202 2-Channel 12-bit A/D. 5 - Micro SD Card. 6 - Header Interface SPI6. 7 - Header Interface SPI7. RETURNS: nothing. }} ' requesting channel 0? If so, easy reset if (channel == 0) ' clear the 161 OUTA[SPI_SEL_CLR] := 0 ' CLR counter OUTA[SPI_SEL_CLR] := 1 ' allow counting return ' else non-null channel, count up to channel... ' first reset the SPI channel counter ' clear the 161 OUTA[SPI_SEL_CLR] := 0 ' CLR counter OUTA[SPI_SEL_CLR] := 1 ' allow counting ' now increment to requested channel ' clock the 161 OUTA[SPI_SEL_CLK] := 0 repeat channel OUTA[SPI_SEL_CLK] := 1 OUTA[SPI_SEL_CLK] := 0 ' end SPI_Select_ChannelI'm not 100% on how to use this, though. I don't understand why "SPI_SEL_CLR" (and others) aren't defined within the object seeing how this code is in the manual for the C3 (why would you need to change these otherwise? Seeing how they are routed on a PCB with traces that will NEVER change). I defined them as constants based on the table in the manual. Do I call this function just before I want to use something that uses SPI? The SD card is the ONLY SPI device being used for my application.
Here is the code I have been trying to get going with no luck:
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 SPI_SEL_CLK = 25 ' SPI Clock 0->1->0 SPI_MOSI = 9 ' SPI MOSI (or DI) SPI_MISO = 10 ' SPI MISO (or DO) SPI_SCK = 11 ' SPI select for microSD card SPI_SEL_CLR = 8 ' SPI select clear 1->0->1 OBJ SD : "fsrw.spin" Serial : "FullDuplexSerial_drv_014.spin" PUB Main Serial.start(31,30,0,9600) Serial.txstringnl2(STRING("Serial works.")) SPI_Select_Channel(5) if(!SD.mount(8)) Serial.txstringnl2(STRING("SD Successfully Mounted!")) else Serial.txstringnl2(STRING("SD Failed to Mount!")) PUB SPI_Select_Channel( channel ) {{ This function sets the active SPI channel chip select on the SPI mux, this is accomplished by first resetting the SPI counter that feeds the SPI select decoder, then up counting the requested number of channels. PARMS: channel : channel 0 to 7 to enable where the channels are defined as follows 0 - NULL channel, disables all on/off board devices. 1 - 32K SRAM Bank 0. 2 - 32K SRAM Bank 1. 3 - 1MB FLASH Memory. 4 - MCP3202 2-Channel 12-bit A/D. 5 - Micro SD Card. 6 - Header Interface SPI6. 7 - Header Interface SPI7. RETURNS: nothing. }} ' requesting channel 0? If so, easy reset if (channel == 0) ' clear the 161 OUTA[SPI_SEL_CLR] := 0 ' CLR counter OUTA[SPI_SEL_CLR] := 1 ' allow counting return ' else non-null channel, count up to channel... ' first reset the SPI channel counter ' clear the 161 OUTA[SPI_SEL_CLR] := 0 ' CLR counter OUTA[SPI_SEL_CLR] := 1 ' allow counting ' now increment to requested channel ' clock the 161 OUTA[SPI_SEL_CLK] := 0 repeat channel OUTA[SPI_SEL_CLK] := 1 OUTA[SPI_SEL_CLK] := 0 ' end SPI_Select_ChannelI'm currently trying to "mount" the SD card and print to my terminal whether or not it worked. I get "Serial works." and nothing else. Shouldn't I at least get one of the terminal print functions with the if, else statements? After that I'd like to figure out how to start logging data to it and then integrate some sensors.
I would greatly appreciate some help from an experienced C3 user. I could normally just bug one of my friends with micro controller questions, but I don't know anyone that uses propellers.
Please help!
Comments
http://www.parallaxsemiconductor.com/an006
Use the special version of the driver attached for the C3. Only the regular versions of the driver are available at the following link. Only the FATEngineStart function needs to be examined to see changes between the different versions of the object that support different hardware. Please read the application also at the link and all the demo files to figure out what is going on. Everything should be quite clear to you.
Thanks,
When you edit the top post, you have to go to Advanced, then change the Prefix.