cancel
Showing results for 
Search instead for 
Did you mean: 

ST9 INTERRUPT FOR SCI

gumina
Associate II
Posted on April 17, 2006 at 08:34

ST9 INTERRUPT FOR SCI

2 REPLIES 2
gumina
Associate II
Posted on May 17, 2011 at 11:37

hello to all,

it is my first post that shipment.

I have a problem with the ST9 F120, I am trying to create a software that to every data received on the serial me kinds a interrupt.

I have connected the ST9 to a hyperterminal I am through SCI1(9,1,9,0), SCI0(5,2,5,1); digit on hyperterminal the SCI0 I would want that it generated a interrupt and that me correspondent to SCI1 wrote the characters on an other hyperterminal but unfortunately this does not happen could even help me with a small code of example? I enclose you mine more soon main and rows SCI.C aspect to yours news thanks

MAIN.C

void main(void)

{

di();

INIT_PLL();

INIT_SCI();

INIT_SCI1();

INIT_SCI_IT();

ei();

spp(P0C_PG);

P0C2R = 0x00;

P0C1R = 0xFF;

P0C0R = 0x00;

P0DR&=0;

while(1)

{

INIT_SCI_IT();

ei();

spp(P0C_PG);

P0DR &= 0x0;

P0DR ^= 0x2;

spp(SCI0_PG);

ToRec=S_RXBR;

if (ToRec != temp)

{

spp(SCI1_PG);

S_TXBR=ToRec;

temp=ToRec;

}

}

spp(P0C_PG);

P0DR ^= 0x80;

}

SCI.C

#include ''sci.h''

#include

#include ''io_port.h''

#include ''define.h''

#include ''device.h''

#include ''ioinit.h''

#include ''string.h''

unsigned char ToReceive;

unsigned int c=0;

void INIT_SCI(void)

{

spp(SCI0_PG);

S_BRGHR = (unsigned char)((SCI_BRGENERATOR & 0xFF00)/256);

S_CHCR = SCI_CHAR;

S_CCR = SCI_MORECLOCK; /*CCR register: TXCLK = OCLK = XRX = CD = 0 */

S_ISR = 0;

S_IDPR = 0;

S_BRGLR = (unsigned char)(SCI_BRGENERATOR & 0x00FF);

IN_TTL(PORT_SCI0_IN, PIN_SCI0_IN);

OUT_AFPP(PORT_SCI0_OUT, PIN_SCI0_OUT);

}

void INIT_SCI1(void)

{

spp(SCI1_PG);

S_BRGHR = (unsigned char)((SCI_BRGENERATOR & 0xFF00)/256);

S_CHCR = SCI_CHAR;

S_CCR = SCI_MORECLOCK; /*CCR register: TXCLK = OCLK = XRX = CD = 0 */

S_ISR = 0;

S_IDPR = 0;

S_BRGLR = (unsigned char)(SCI_BRGENERATOR & 0x00FF);

IN_TTL(PORT_SCI1_IN, PIN_SCI1_IN);

OUT_AFPP(PORT_SCI1_OUT, PIN_SCI1_OUT);

}

void INIT_SCI_IT(void)

{

spp(SCI0_PG);

S_IVR = (IT_SCI_VECT & 0xF8);

S_IDPR &= SCI_MASK;

S_IDPR |= PRIO_SCI;

S_IMR &= SCI_MASK;

S_IMR |= Sm_rxdi;

}

#pragma interrupt INTSCI_Receive

void INTSCI_Receive(void)

{

#ifdef NO_SAVE_RESTORE_PPR_IN_IT

SAVE_PAGE;

#endif

spp(SCI0_PG);

ToReceive=S_RXBR;

spp(SCI1_PG);

S_TXBR=ToReceive;

spp(SCI0_PG);

S_IMR &= ~Sm_rxa;

S_ISR &= ~Sm_rxap; /*clear pending bits*/

S_IMR &= ~Sm_rxdp;

#ifdef NO_SAVE_RESTORE_PPR_IN_IT

RESTORE_PAGE;

#endif

di();

}

kapil
Associate II
Posted on May 17, 2011 at 11:37

Pls find below an example software for one of the project

I hope this will help

My advise is to try running the SCI independentely first then both at the same time.

-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- INCLUDE FILES -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/

#include ''sci.h''

#include

#include

#include

#include ''define.h''

#include ''device.h''

#include ''ioinit.h''

/*-*-*-*-*-*-*-*-*-*-*-*-*-*-* LIBRARY FUNCTIONS -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/

//Routine name : SCI_Receive_Byte

//Return the value of the receiver buffer

unsigned char SCI_Receive_Byte(void)

{

spp(SCI0_PG);

return(S_RXBR);

}

//Routine name : SCI_Send_Msg

//Send a string to the SCI using poolling

void SCI_Send_Msg(const char msg[])

{

unsigned char i;

spp(SCI0_PG);

for (i=0;msg[i]!='\0';i++)

{

S_ISR &= ~Sm_txbem; //Clear pending bit

S_TXBR = msg[i];

while (!(S_ISR & Sm_txbem)); //Wait the end of transmission

}

}

/*-----------------------------------------------------------------------------

ROUTINE Name : INIT_SCI

Description : Initialization of general parameters devoted to the SCI :

- Baud Rate Generator : 2400 bauds

- Characters. : Eight data bits, one stop bit, odd parity.

- Pins...

Comments : The baud rate generator must be initialized following this structure

(BRGHR first and BRGLR at the end)

-----------------------------------------------------------------------------*/

void INIT_SCI(void)

{

spp(SCI0_PG);

S_BRGHR = (unsigned char)((SCI_BRGENERATOR & 0xFF00)/256);

S_CHCR = SCI_CHAR;

S_CCR = SCI_MORECLOCK; /*CCR register: TXCLK = OCLK = XRX = CD = 0 */

S_IDPR = 0;

S_ISR = 0;

S_BRGLR = (unsigned char)(SCI_BRGENERATOR & 0x00FF);

OUT_AFPP(PORT_SCI0_OUT, PIN_SCI0_OUT);

}

/*-----------------------------------------------------------------------------

ROUTINE Name : INIT_SCI_IT

Description : Initialization of the IT : vector, priority.

Comments :

-----------------------------------------------------------------------------*/

void INIT_SCI_IT(void)

{

spp(SCI0_PG);

S_IVR = (IT_SCI_VECT & 0xF8);

S_IDPR &= SCI_MASK;

S_IDPR |= PRIO_SCI;

}

/*-----------------------------------------------------------------------------

ROUTINE Name : SCI_SendByte

Description : It sends byte ToSend to serial link

This routine also enables end of transmission IT.

Comments :

-----------------------------------------------------------------------------*/

void SCI_SendByte(unsigned char ToSend)

{

di();

spp(SCI0_PG);

S_IMR &= SCI_MASK;

S_IMR |= Sm_txdi;

S_TXBR = ToSend;

ei();

}

/*-----------------------------------------------------------------------------

ROUTINE Name : INTSCI_TransmitReady

Description : It is the interrupt routine which occurs after the transmission

of one character.

If 10 bytes have been transfered, it disables the IT and so stops

the transmission.

Comments :

-----------------------------------------------------------------------------*/

#pragma interrupt INTSCI_TransmitReady

void INTSCI_TransmitReady(void)

{

#ifdef NO_SAVE_RESTORE_PPR_IN_IT

SAVE_PAGE;

#endif

#ifdef NO_SAVE_RESTORE_PPR_IN_IT

RESTORE_PAGE;

#endif

}