2005-12-22 05:47 PM
2005-12-19 07:40 PM
Dear sir,
I am developing a firmware in C(cosmic) which needs SCI communication.I need to know certain things in SCI.Pls help. Below is my sample code. i haven't put the header files where i have defined variables & function prottype. const unsignned char tx_buff[6]={0x41,0x42,0x43,0x44,0x45,0x46}; main.c ************* void main() { // ST7 port initialization here sci_init() // sci initialization. defined in peri.c // enable interrupts while(1) { //task 1 sci_tx() // data transmit .defined in peri.c // task2 2 sci_rx() // data receive ,not written code. //....task n } } peri.c ************* void sci_init() { unsigned char dummy; SCICR1 =0x00; SCICR2 =0x00; dummy = SCISR; dummy = SCIDR; // these 2 steps are done to reset any pending interrupts. SCIBRR = BRR_SPEED; // #define BRR_SPEED 0xD2 SCICR1 = 0x00; // 8 bit word M = 0 SCICR2 = 0x08; } void sci_tx() { unsigned char i; for(i=0;i { SCIDR=tx_buff[i]; while(!bittest(SCISR,7)); } } my questions: 1) are the steps for sci communication in the above code OK? pls suggest if anything to be added? 2) datasheet says ''Setting the TE bit drives the SCI to send an idle frame before the first data frame.''AS SCI starts with IDLE data frame.And i don't want to transmit that data .How should i omit/prevent that? 3) In datasheet's ''sci transmission procedure'' section it is said that access the SCISR register and then write the data to be send into SCIDR register.It will clear the TDRE flag.if i follow this then how do i be sure that data has really transmitted out ?? 4)But i am writting the data to be send into SCIDR first then reading the TDRE flag to check if data has been transmitted or not ? if data is transmitted then TDRE will be set?is it a correct sequence ? 5) i will be using my tx and rx routine in a loop along with other routine.So transmission and reception routine will need to be reliable.Please advise me if anything to be modified considering my code above. I will be thakful to receive help on above queries. Thanks Arup2005-12-20 02:59 AM
As you have SCI_Init after reset, it is not neccesary to clear SCICRx registers, because 0x00 is their reset value. The same with pending interrupts - there will be no pending interrupt after reset. And, if interrupts are not enabled, micro takes no care about that flags.
Nevertheless, it is not neccessary to made dummy variable, simple SCISR; will be enough. Compiler will be forced to read register and throw away readed value. Maybe, you would like to set extended prescalers as well to achive precise baud rate? Ad 3 - when data are transferred out, TDRE flag will be set.2005-12-22 05:34 PM
thanks Mr. setler.
1) could you tell me which approach is good? a) read SCISR and then write data to SCIDR (as per datasheet) OR b) write data to SCIDR and then check for TDRE bit by reading SCISR. 2) Unlike hardware I2C in SCI communication user don't have to set START bit or STOP bit .And TC bit is set after the stop bit. So i want to know how hardware internally set the TC bit.I mean to say how it knows that ''This is the time for setting STOP bit and ..then setting TC bit.....Is there any time duration calculation concept ?Is the hardware counts the time after last data byte tranferred and compare with the internal threshold and if it elapses it set the STOP and TC bit ?? How is it done....? I will be happy to know? Thanks, Arup2005-12-22 05:47 PM
I got the answer for my point no 2)
The data is transmitted and received as a fram not like i was thinking. the frame will be IDLE LINE + A START BIT + A DATA WORD(8 bit or 9 bit) + A STOP bit. Now i want to know how to prevent the IDLE frame to come into my actual received data.?? Thanks, Arup