Skip to main content
Visitor II
August 17, 2004
Question

SCI receiver

  • August 17, 2004
  • 6 replies
  • 949 views
Posted on August 17, 2004 at 05:27

SCI receiver

    This topic has been closed for replies.

    6 replies

    Visitor II
    July 9, 2004
    Posted on July 09, 2004 at 10:25

    Hi,

    I'm building an SCI receiver with an ST72F264G2. But it doesn't work.

    It's an 250kBAUD 1startbit + 8databits + 2stopbits serial protocol

    The interrupt routine is called, but the SCIDR does not contain the right data.

    Here is the code (summarised):

    void main(void)

    {

    int tel, tel2;

    int rood, blauw, groen;

    unsigned char *ER=(unsigned char *)0x1020;

    PADDR=0xef; //1 1 1 0 1 1 1 1

    PAOR=0xef; //1 1 1 0 1 1 1 1

    PBDDR=0xff;

    PBOR=0xff;

    ClrBit(PADDR,5); //input

    ClrBit(PAOR,5); //input

    SCIBRR = 0x01; //0000 0001 SCI Baudrate Register

    SCICR1 = 0x10; //0001 0000 SCI Control Register1

    SCICR2 = 0x24; //0010 0100 SCI Control Register2

    rood = 0;

    groen = 0;

    blauw = 0;

    datagroen = 0;

    datablauw = 0;

    datarood = 0;

    startkanaal = 0;

    aantaldata = 0;

    DMX_OK = 0;

    _asm(''rim'');

    while(1){

    SPI_master(datablauw, datarood);

    }// end while(0)

    }//End void main(void)

    @interrupt void UART_RX(void)

    {

    if (ValBit(SCISR,RDRF)) //

    {

    if (ValBit(SCISR,NF)) // Noise?

    {

    DMX_OK = 0;

    t = SCIDR;

    }

    else if (ValBit(SCISR,FE))

    {

    if (SCIDR == 0) // break?

    {

    ontvangstkanaal = 0;

    DMX_OK = 1;

    }

    else

    {

    t = SCIDR;

    DMX_OK = 0;

    }

    }

    else

    {

    if (ontvangstkanaal == 511)

    DMX_OK = 0;

    if (!ValBit(SCICR1,T

    ) DMX_OK = 0;

    if (DMX_OK == 1)

    {

    if (ontvangstkanaal == DMX_kanaal) datarood = SCIDR; if (ontvangstkanaal == DMX_kanaal+1)

    datagroen = SCIDR; if (ontvangstkanaal == DMX_kanaal+2)

    datablauw = SCIDR;

    }

    ontvangstkanaal++; }

    }

    t = SCIDR; // 2de stap voor reset

    }

    Visitor II
    July 12, 2004
    Posted on July 12, 2004 at 07:02

    I was reading the datasheet of ST72F264, but i can't find any configuration of 2 stopbits? Mayby you can solve it by configure 9 data bits?

    Visitor II
    August 9, 2004
    Posted on August 09, 2004 at 09:38

    Hello,

    Now my holidays are over this problem is actual again.

    My SCI receiver still doesn't work.

    @Moppie:

    The first stopbit is bit 9 in the dataword. The second one is the real stopbit.

    The noise flag is set after almost every reception, and sometimes the framing-error flag. The Baudrate should be right (set at 250kBaud).

    If anyone has an idea what is wrong or has a piece of working code, i'd be helped.

    The device is a very simple SCI-receiver, so i think the software in the ST7 software library is too complicated for this application. Maybe I'm wrong???

    Thanks!

    [ This message was edited by: joble on 10-08-2004 11:01 ]
    Visitor II
    August 10, 2004
    Posted on August 10, 2004 at 09:57

    Hi,

    I have simplified the interrupt routine to this code:

    * The processor waits for a break and then sets t = 0;

    * t is incremented each time a frame is received after the break

    * when t has reached the value 2 the frame is saved into 'datarood'

    * the processor waits for a break again (t is not incremented anymore)

    By doing this the second frame received is send to the datarood register

    @interrupt void UART_RX(void)

    {

    if (ValBit(SCISR,RDRF))

    {

    if (ValBit(SCISR,FE))

    {

    if (SCIDR == 0) // FE + 00 data ==> Break

    t = 0; // there is a break ==> reset counter

    }

    if (t == 2) // 2nd frame --> save data tot datarood

    datarood = SCIDR;

    if (t <= 2) // increase counter

    t++;

    }

    }

    But... The output still makes no sense. It seems that the break character is not recognised.

    Any ideas

    [ This message was edited by: joble on 10-08-2004 13:37 ]

    Visitor II
    August 11, 2004
    Posted on August 11, 2004 at 10:38

    Hi,

    In the meanwhile i have changed my code. Now i use the SCI-functions of the ST7 library and get exactly the same result.

    The SCI does not recognise any break. Framing errors en noise errors are found constantly.

    The SCIBRR register is set to 0x01 what shoud be correct for 250kBAUD.

    Wordlength = 9 bits, (last bit is stopbit and ignored for now)

    I have attached the c file of the code based on the ST7lib

    ________________

    Attachments :

    main.C : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0AN&d=%2Fa%2F0X0000000bUg%2Fka0bb3V94oEKOwcvUfY5XDjGoFUSIIYnRD83ltGKr7U&asPdf=false
    Visitor II
    August 17, 2004
    Posted on August 17, 2004 at 05:27

    Hello,

    I found out what was going wrong

    .

    The SCIBRR register is now set to 0x00 instead of 0x I'm using an 8MHz xtall, so Fcpu = 4MHz (and not 8MHz as i thought).

    The only problem i still have is that the ''received data counter'' i made sometimes fales. When i ask for channel 145, i sometimes get the data of But this must be a small mistake somewhere.

    EDIT: OK, it was indeed a small mistake!!!

    Greets!

    [ This message was edited by: joble on 17-08-2004 09:39 ]

    [ This message was edited by: joble on 17-08-2004 10:03 ]