Shop OBEX P1 Docs P2 Docs Learn Events
BS2 Master - Slave — Parallax Forums

BS2 Master - Slave

TumblerTumbler Posts: 323
edited 2009-10-19 16:02 in BASIC Stamp
Hello,

I'm planning to make a bs2pe used as an eeprom controller.
see picture...

About the eeprom controller:
i want to make a FAT-based eeprom controller: sending data, receiving data, get directorys etc...
The internal eeprom of the slave would be used for storing package information (date, time, id, package length, wich eeprom is used, address data,...)

I have read an article from Jon Williams ( a tale of two stamps), but as i can see the master can only talk to the slave? or is it possible in two ways?

And this slave code: SERIN SIOpin\FCpin, N2400, 200, LCD_Update, [noparse][[/noparse]ioByte]
does it mean that the slave only can receive data if the FCpin is high? that's not clear for me.
and can i use the same code·for the master? so i can talk in two ways?

regards
898 x 350 - 104K

Comments

  • dev/nulldev/null Posts: 381
    edited 2009-10-19 09:56
    Yes you can talk both ways. That's why you are using flow control. This will prevent one sender from sending data until the receiver is ready. SERIN and SEROUT will control the flow pin, you don't have to do anything with it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't worry. Be happy
  • TumblerTumbler Posts: 323
    edited 2009-10-19 12:32
    Ok Dev/null

    After some tests, this is what i have:

    Master (a basic stamp2)
    SIOpin CON 14 ' serial I/O
    FCpin CON 15 ' serial flow control
    CMD     CON 250 'cmd signal
    ACK     CON 254 'ack signal
    ERR     CON 255 'error signal
    DIR     CON 0   'dir command
    GDATA   CON 1   'get command
    PDATA   CON 2   'put command
    i VAR Byte
    j VAR Byte
     
    Main:
      SEROUT SIOpin\FCpin, Baud, [noparse][[/noparse]CMD,PDATA]  ' send put command to slave
      DEBUG "put command send...",CR
    
      ' now wait for ACK signal
      SERIN SIOpin\FCpin, Baud,[noparse][[/noparse]WAIT(ACK),j]
      DEBUG "ack + answer reveived... Answer:",DEC j,CR
    
    END
    
     
    Ready:
      DEBUG "ack received ",CR
      GOTO Main
     
    TimeOut: '--> [b]not used this time
    [/b]   DEBUG "no ack received ",CR
    

    SLAVE ( a BS2pe)

    CMD     CON 250 'cmd signal
    ACK     CON 254 'ack signal
    ERR     CON 255 'error signal
    DIR     CON 0   'dir command
    GDATA   CON 1   'get command
    PDATA   CON 2   'put command
    ' -----[noparse][[/noparse] Variables ]-------------------------------------------------------
    i VAR Byte
    
    Main:
    DO
      'wait for CMD command, with command type(i)
      SERIN SIOpin\FCpin,Baud,500,Check,[noparse][[/noparse]WAIT (CMD), i]
      DEBUG "Reveived from master: ",DEC i ,CR
      BRANCH i, [noparse][[/noparse]Directory, GetData, PutData]
      'We received an illegal command
      DEBUG "Error command...",CR
      DEBUG "Send Ack + error back",CR
      SEROUT SIOpin\FCpin,Baud,[noparse][[/noparse]ACK,ERR]
    LOOP
     
    Check:
      'do something check here
      GOTO main
     
    Directory:
      'we received a DIR command
      PAUSE 1000    'slave is busy stamp
      SEROUT SIOpin\FCpin,Baud,[noparse][[/noparse]ACK,240]
      GOTO Main
     
    GetData:
      'we received a GET command
      SEROUT SIOpin\FCpin,Baud,[noparse][[/noparse]ACK,222]
      GOTO Main
     
    PutData:
      'we received a PUT command
      PAUSE 3000  'slave is a very busy stamp
      SEROUT SIOpin\FCpin,Baud,[noparse][[/noparse]ACK,200]
      GOTO Main
    
    

    With these examples i can send a DIR,GET and PUT command to the slave. (slave answers with a ACK and a dec value)
    But how can i prevent to send a command while the slave is busy?
    i think i have to check the FCpin, but i don't know how to do it.
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2009-10-19 15:37
    Tumber,

    Is it not working?

    The SERIN commands in the slave and the master control the output state of the FCpin. When the slave hits a SEROUT, it checks its FCpin "clear to send" as an input to see that the master is ready. And vice versa, when the master hits a SEROUT, it checks its FCpin "clear to send" as an input to see that the slave is ready to receive. So the flow control goes both ways.

    Be sure you have ~1kOhm resistors in the lines between the two stamps, just in case there is a contention. That shouldn't happen in this program but it is a precaution.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • TumblerTumbler Posts: 323
    edited 2009-10-19 15:57
    Tracey,

    The code above is working, but when the master sends 2 commands i don't receive the ACK anymore. In fact, i don't receive anything from the slave.
    example (2 commands)
    SEROUT SIOpin\FCpin, Baud, [noparse][[/noparse]CMD,PDATA]· ' send put command to slave
    pause 10
    SEROUT SIOpin\FCpin, Baud, [noparse][[/noparse]CMD,GDATA]· ' send get command to slave

    Do i have to check the FCpin before i send a command?
    I tried if the pin is low or high, but it takes me to nothing.

    ·
  • TumblerTumbler Posts: 323
    edited 2009-10-19 16:02
    Ahhhhh, i forgot to check the ACK signal. freaked.gif

    This is working now...
        'send first command
        SEROUT SIOpin\FCpin, Baud, 1000,TimeOut,[noparse][[/noparse]CMD,0]  ' send put command to slave
        SERIN SIOpin\FCpin, Baud,[noparse][[/noparse]WAIT(ACK),j]
        DEBUG "ack + answer reveived... Answer:",DEC j,CR
        
        PAUSE 1000 'let's take a break
        
        'send second command
        SEROUT SIOpin\FCpin, Baud, 1000,TimeOut,[noparse][[/noparse]CMD,1]  ' send put command to slave
        SERIN SIOpin\FCpin, Baud,[noparse][[/noparse]WAIT(ACK),j]
        DEBUG "ack + answer reveived... Answer:",DEC j,CR
    


    yihaa, it's working... hop.gif
Sign In or Register to comment.