Shop OBEX P1 Docs P2 Docs Learn Events
uALFat Baud Rate — Parallax Forums

uALFat Baud Rate

Kit MortonKit Morton Posts: 39
edited 2007-08-29 15:01 in Propeller 1
Hi all,
In my latest project I needed FAT32 support so I got a uALFat chip, and I am trying to interface it to the propeller.
I am using the serial interface with the FullDuplexSerial object. And I can talk to the the chip but I want to use a baud rate over 9600. But when I try to change the baud rate of the chip, then change the serial objects baud rate, I can't communicate with the chip any more sad.gif.
Has anyone tried to change of this chip, and if so what did you have to do to make it work?
Or should I just bag the Serial and go for SPI?
Thanks
-Kit

Comments

  • tekochiptekochip Posts: 56
    edited 2007-08-27 13:34
    I had the same trouble, everything was fine at the lower baud rates, but it couldn't communicate at the higher rates.· All the timing was spot on, I just assumed it was some trouble with the serial driver not being able to handle full duplex at the higher rates.· I think I may have gotten it up to 115K without trouble, and then decided that I really needed to go I2C.· The SPI can go faster, but I was disappointed by the pin count required for SPI.

    For the I2C you can get up to the 400KHz spec without trouble, and since you already have to dedicate pins for SDA and SCL, the only penalty is the handshaking line.· I only use one handshaking line to see if the uALFAT still has data.· The only precaution I can give is that you'll need a START, COMMAND, DATA, STOP for each character, so it's twice as chatty as it needs to be.· Even still,·you can move 4K images in 400mS.

    Oh yea, the uALFAT also has a 512 byte buffer, so you'll get 512 bytes then the uALFAT will go silent for·5 mS while it fetches more data.· I was streaming audio and needed a buffer to get over the dead period.

    ·
  • Kit MortonKit Morton Posts: 39
    edited 2007-08-28 14:35
    Thanks for the tip.
    I tried to do this, but I couldn't figure out how to make the I2C object work in the rite way.
    Could you post some code snippets for how you implemented it.

    Thank you
    -Kit
  • tekochiptekochip Posts: 56
    edited 2007-08-29 15:01
    Sure, I started with the Hydra I2C driver, but it got so gutted that very little of the original remains.· It's sort of like George Washington's axe; I had to replace the handle, and I had to replace the blade.


    {*******************************************ReadAlfat*********************************************
    It's a pain, but the Alfat can only read one byte at a time, so all transfers are twice larger
    than the really need to be because you have to address the chip all over again
    **************************************************************************************************}
    ReadAlfat
                  '--- Setup Normal Condition ---
                  andn     dira, HandShake          'Make sure it's an input
     
    :Loop
                  'Wait until ready
                  mov      dataByte, ina                    'Grab the handshaking line
                  test     dataByte, HandShake wz           'Is it low?
            if_z  jmp      #:Loop                  '        Yes, cycle until ready
                                                             
                                                             
                  call    #StartCondition                   'generate start condition
                  mov      dataByte, #$A5                   'The Alfat's read address
                  call    #SendByte                         'send device address byte
                  call    #CheckAck                         'check for ACK from eeprom
                                                     
                        '--- Read Byte ---
                  call      #ReceiveByte                    'receive byte
                  wrbyte    dataByte,BufferAddress          'store received byte into buffer
                  add       BufferAddress,#1                'increment buffer address                                                
                  sub       paramByteCount,#1    wz         'decrement number of bytes left
                  wrlong    paramByteCount,byteCountAddr    'let other cogs know the progress so far
                                                             
                                                             
                                                             
                  test    LongMax,#1    wc                  'set C to 1 for "No ACK" (meaning "done")
                  call    #SendBit                          'send "ACK"/"No ACK"
                  call    #StopCondition                    'generate stop condition
            if_nz jmp     #:Loop                            'loop                                                                                  
                  
    ReadAlfat_ret
                  ret
     
     
    {*****************************************StartCondition*****************************************
    I2C is supposed to idle SCL and SDA high, and I believe this has caused a number
    of timing problems, so everything will be changed to make it more robust and faster
    *************************************************************************************************}
    StartCondition
                  or       outa,datMask             'Make sure data and clock are high
                  or       outa,clkMask             'pull clock high
                  or       dira,datMask             'set data pin to output
                  or       dira,clkMask             'Verify clock is too
                  
                  mov      timer, #T_HIGH           'Get the high period
                  add      timer, cnt               'Add the time
                  waitcnt  timer, #T_HIGH           'Wait and get ready for next high period
                  
                  andn      outa,datMask            'pull data low
                  waitcnt  timer, #T_HIGH           'Wait and get ready for next high period
                  andn      outa,clkMask            'pull clock low
                  waitcnt  timer, #T_HIGH           'Wait and get ready for next high period              
    StartCondition_ret
                  ret                            
    
    
    

    There is no error checking if the uALFAT doesn't respond because in my application it wouldn't matter, the machine would be broken, so you may want to add some sort of abort to the handshaking loop.· The main issue with the Hydra driver is the way waitcnt is used for bit timing.· It·gets a little flakey when you·reach full speed·and that's why I·wanted to rewrite it.· You'll want to make sure that each transfer starts with reloading your timer, or else waitcnt will roll over and you'll be stuck waiting·50 seconds for the next bit to shift out.
    ·
Sign In or Register to comment.