arup
Member level 2

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<6;i++) //transmitting 6 bytes ...
{
SCIDR=tx_buff;
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
Arup
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<6;i++) //transmitting 6 bytes ...
{
SCIDR=tx_buff;
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
Arup