Shop OBEX P1 Docs P2 Docs Learn Events
propeller c3 spi problem — Parallax Forums

propeller c3 spi problem

ggg558877ggg558877 Posts: 40
edited 2013-02-01 21:05 in Propeller 1
Hi everyone
I have some problem about c3 spi
now i want to use c3 spi A/D to get the data and write into SD card
if I separately use them it ok
but when i use together the A/D value always 0
how can i use A/D and SD card together?
thanks
CON

  _clkmode = xtal1 + pll16x
  _xinfreq = 5_000_000
con
  RX1 = 31                                                      ' programming / terminal
  TX1 = 30
  
  SDA = 29                                                      ' eeprom / i2c
  SCL = 28

  SD_CS    = 25  
  SD_DI    = 9
  SD_CLK   = 11
  SD_DO    = 10
OBJ
pp   : "po"
sdcard : "dave_fsrw"
term   : "FullDuplexSerial"
num    : "numbers" 
var
    long g_temp1
PUB demo | check ,value 

    term.start(31, 30, 0, 115200)
    pp.SPI_Init
    check := \sdcard.mount_explicit(SD_DO, SD_CLK, SD_DI, SD_CS)  
    check := \sdcard.popen(string("NMEA.txt"), "w")
    'value:=10
    repeat    10
       AD_Test
       term.dec(g_temp1)
                        'wind  direction
       term.tx(13)
       sdwrite
       WaitCnt(ClkFreq+ Cnt)

    sdcard.pclose
    \sdcard.unmount
PUB AD_Test 
    pp.AD_Init
    g_temp1 := pp.AD_Read( 0 )
PUB  sdwrite  
      sdcard.pputs(num.ToStr(g_temp1,10))

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2013-01-31 22:51
    ggg558877 wrote: »
    how can i use A/D and SD card together?
    The SD driver takes exclusive ownership of the SPI select h/w. Once it has control no other driver is able to reset the CS counter. IOW you'd need a more friendly SD driver.
  • ggg558877ggg558877 Posts: 40
    edited 2013-01-31 22:58
    kuroneko wrote: »
    The SD driver takes exclusive ownership of the SPI select h/w. Once it has control no other driver is able to reset the CS counter. IOW you'd need a more friendly SD driver.

    so i can't get the A/D value then write into SD card?
  • kuronekokuroneko Posts: 3,623
    edited 2013-01-31 23:07
    ggg558877 wrote: »
    so i can't get the A/D value then write into SD card?
    Not with the drivers you're using right now. The way SPI selection is implemented means that all involved drivers have to share in some way.
  • ggg558877ggg558877 Posts: 40
    edited 2013-02-01 00:18
    kuroneko wrote: »
    Not with the drivers you're using right now. The way SPI selection is implemented means that all involved drivers have to share in some way.

    I have try to use fsrwFemto and sdspiFemto but it dosen't work
    I don't know how to solve my problem
    are there someone had used propeller c3 both A/D and SD card?
  • StefanL38StefanL38 Posts: 2,292
    edited 2013-02-01 10:53
    If the driver is completely stopped and started again; So the code would collect data for some time and then
    from time to time the SD-Card-driver is started to write the data and then stopped again? Would that work?
    Surely the C3 has everything "on board" but how about connecting an external SD-Card-socket to some pins to keep the SD-card
    away from the SPI-bus?

    best regards
    Stefan
  • ggg558877ggg558877 Posts: 40
    edited 2013-02-01 20:41
    StefanL38 wrote: »
    If the driver is completely stopped and started again; So the code would collect data for some time and then
    from time to time the SD-Card-driver is started to write the data and then stopped again? Would that work?
    Surely the C3 has everything "on board" but how about connecting an external SD-Card-socket to some pins to keep the SD-card
    away from the SPI-bus?

    best regards
    Stefan

    Hi StefanL38
    I try to completely stopped and started the driver but in the sd card only show one value
    because if i re-start the SD-Card-driver the value before will clear
  • Mike GreenMike Green Posts: 23,101
    edited 2013-02-01 21:05
    The SD card and ADC drivers need to be rewritten or modified significantly to allow them to share the SPI selection circuitry. The closest I've seen to a pair of drivers that work properly is in the C3 version of Sphinx and the version of FemtoBasic that uses those drivers. Even then, there were some problems and I didn't have time to completely solve them. In modifying the drivers, I was trying to make it possible to use all of the SPI devices, at least from the same cog. If you had to use more than one cog, you had to add your own lock / semaphore around calls to the drivers.

    Make sure you close the file before stopping the SD card driver.
Sign In or Register to comment.