PDA

View Full Version : Ideas


kneedown
08-17-07, 11:52 AM
I've got a program running in flash on an IsoPodX which gets data from 4 ADCs and 4 PWMs and does some processing of the data to enable it to be output via SCI1 in string form to an SD card board.

The SD card has to be sent a command before every batch of data telling it how many bytes to expect. My problem is that the data arriving at the SD card is scambled such that the command gets read as incoming data which of course then messes up the following data. I've checked that the command contains the right no. of bytes info and I've tried running the state machines at much lower frequency and operating the SCI1 at lower baud rates all with no improvement. I've got RX and TX buffers and I've tried larger and smaller TX buffers.

Can you offer any other avenues that I can pursue?

nmitech
08-17-07, 02:15 PM
I am not quite clear what type of protocol you use to communicate between two devices other than serial communication. I think it's better if you can show us your code with comments on what you are try to do.

kneedown
08-17-07, 03:22 PM
OK Here's some relevant extracts of code (sorry there's so much and as I'm a beginner with Isomax it may be poorly constructed):
DECIMAL HERE 8 ALLOT CONSTANT BUFFER1 EEWORD
BUFFER1 8 SCI1 RXBUFFER
DECIMAL HERE 500 ALLOT CONSTANT BUFFER2 EEWORD
BUFFER2 500 SCI1 TXBUFFER
...................................................................
... then in this gap I define a load of variables ...
...................................................................
The following word takes the collected data from the TRANSMIT-CHAR word and sends it character-by-character to the SCI1
: CHRS-OUT \ str cnt --X output characters one at a time
CNT !
CNT @ 0
DO
DUP I + @ \ get next char from string
I XXARRAY + ! \ store in array
LOOP DROP \ drop adr on stack
CNT @ 0 DO
I XXARRAY + @ SCI1 TX \ transmit ASCII value
LOOP
; EEWORD

: TRANSMIT-CHAR
TPS C@ 0 <# #S #> CHRS-OUT
2C SCI1 TX
MAP C@ 0 <# #S #> CHRS-OUT
2C SCI1 TX \ var to ascii str then output
.............................................................
... there are five other similar sets in this gap
.............................................................
SPEED C@ 0 <# #S #> CHRS-OUT
0D SCI1 TX \ var to ascii str then output
30 ENDT C! \ this is used for debugging purposes
; EEWORD

The following word counts the total number of characters to be sent via SCI1
: GET-COUNT \ count the number of characters to send to uMMC
TPS C@ 0 <# #S #> SWAP DUMMY ! CNT ! CNT @ CHARNO C@ + CHARNO C!
MAP C@ 0 <# #S #> SWAP DUMMY ! CNT ! CNT @ CHARNO C@ + CHARNO C!
.....................................................
... there are five similar sets in this gap
.....................................................
SPEED C@ 0 <# #S #> SWAP DUMMY ! CNT ! CNT @ CHARNO C@ + CHARNO C!

; EEWORD

The following word sends a command to the SD card in the form
W 1 nn{cr) where nn is the total number of characters to be sent
: PREPSEND
HEX

57 SCI1 TX 20 SCI1 TX 31 SCI1 TX 20 SCI1 TX
C1 C@ SCI1 TX C2 C@ SCI1 TX 0D SCI1 TX
; EEWORD

Finally the following word causes the others above to be called
: GETDATA
RUNCOUNT C@ 1 + RUNCOUNT C! RUNCOUNT C@ \ these are for
ENDT C@ 30 = IF \ debugging
31 ENDT C! \ purposes

ADC0 ANALOGIN TPS C!
ADC2 ANALOGIN MAP C!
.........................................................................
... there are two more ADCs and three PWMs in this gap
..........................................................................
PWM-TB2 SPEED C!
HEX 8 CHARNO C! \ this adds 8 characters into the total to
\ account for commas and cr
GET-COUNT \ this word totals the other chars to be sent
CHARNO C@ 1 10 */MOD C1 C! C2 ! \ this takes the total and
C1 C@ 30 + C1 C! C2 C@ 30 + C2 C! \ splits it into two char
PREPSEND \ this word sends the command to the SD card
TRANSMIT-CHAR \ this word turns the data into strings
\ and sends it char by char to SCI1
ELSE \
MISS C@ 1 + MISS C! \ these are for debugging purposes
THEN \
; EEWORD

A state machine calls the word GETDATA shown above every 50,000 cycles. I haven't shown the PWM input words as they are as given in the doc examples.

nmitech
08-18-07, 09:31 AM
From your code, it seem to me this is an one way communication. There is no such handshaking or somekind of talking back and forth from the two devices other than one (IsoPodX) is sent and the other (uMMC) is received . So instead of lower the serial baud rate i would make them communicate faster as possible, maybe at 115,200 bps and most likely you have to have serial buffer on your uMMC as well. Becaue your uMMC board also need some time to access the SD card. You may keep the machine runs at slow speed as possible. 50,000 cycles is good for your testing in my opinion.

To setup for SCI1 talks at 115,200 you can write data direct to its baud register, HEX 16 F10 ! since the predefine BAUD only takes 16-bit decimal value .

kneedown
08-19-07, 08:53 AM
...
To setup for SCI1 talks at 115,200 you can write data direct to its baud register, HEX 16 F10 ! since the predefine BAUD only takes 16-bit decimal value .


Thanks for your help. I've tracked down the main problem - the no. of bytes figure being sent was wrong. I've corrected this but still see what appears to be occasional data loss in transmission via SCI1. Could you give the way to setup for other baud rates in a similar way to that given for 115200?

nmitech
08-21-07, 10:30 AM
The fomula for calculating the baud rate is,
SCI Baudrate= IPBus clock/(16 x SBR)
or,
SBR=IPBus clock/(16 x SCI Baudrate)

Where IPBus Clock is 40Mhz
and SBR bit contains a value of 1 to 8191

For detail on Baud rate generation, please see chapter 12.4.2
http://www.freescale.com/files/dsp/doc/user_guide/DSP56F801-7UM.pdf