Announcement

Collapse
No announcement yet.

Serial com problem

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Serial com problem

    Hi,

    I'm sending characters to RX pin #30 of uLCD-43PT, but nothing is happend on screen.

    I checked with another terminal and the 'A' , 'B' , 'C' , 'D' , 'P' characters are coming in 9600 baud into the RX pin.

    Please see attached code:

    The "Video2" and "image5" are shown on screen, and then it stays in final loop in "image5", so the case statments do nothing.

    What am i do wrong?

    ====================
    Code:
    =====================================================================================

    #platform "uLCD-43PT"

    #inherit "4DGL_16bitColours.fnc"

    #inherit "VisualConst.inc"

    #inherit "DiExMonitorConst.inc"

    #inherit "PrintDiskGoldelox.inc"

    #inherit "LedDigitsDisplayGoldelox.inc"

    var combuf[24]; // 24 vars = 48 bytes
    var combuffer[1]; // 24 vars = 48 bytes
    var page ;



    func main()
    var chr,char, e, e2, stat;
    var numx, dir, colr, redo, numt ;

    e := 0;
    e2 := 0;

    gfx_Set(SCREEN_MODE,LANDSCAPE) ;
    gfx_Set(CONTRAST,5) ;
    numx := 0 ;

    com1_Reset();

    var frame ;
    // Uncomment the following if uSD images used.
    putstr("Mounting...\n");
    if (!(disk:=file_Mount()))
    while(!(disk :=file_Mount()))
    putstr("Drive not mounted...");
    pause(200);
    gfx_Cls();
    pause(200);
    wend
    endif
    gfx_TransparentColour(0x0020);
    gfx_Transparency(ON);

    hndl := file_LoadImageControl("DIEXMO~1.dat", "DIEXMO~1.gci", 1);


    // image1 1.0 generated 30/05/2014 11:38:29
    //img_Show(hndl,iimage1) ;
    // pause(5000);
    for (frame := 0; frame <= 80; frame++)


    // Video2 1.0 generated 22/08/2014 00:39:00
    img_SetWord(hndl, iVideo2, IMAGE_INDEX, frame) ; // where frame is 0 to 133
    img_Show(hndl,iVideo2) ;



    // video1 1.0 generated 21/08/2014 16:49:25
    // img_SetWord(hndl, ivideo1, IMAGE_INDEX, frame) ; // where frame is 0 to 604
    // img_Show(hndl,ivideo1) ;

    pause(1) ;

    next


    gfx_Set(OUTLINE_COLOUR, DARKOLIVEGREEN); // set outline colour, gfx_Cls() will draw outline
    gfx_Cls();

    // Image5 1.0 generated 22/08/2014 09:54:02
    img_Show(hndl,iImage5) ;

    /*
    txt_Set(FONT_ID, 0);
    txt_MoveCursor(0,1); // reset cursor to line 1, column 2
    putstr("Serial Echo\n9600 baud");
    */
    setbaud(BAUD_9600); // 9600 baud comms
    stat := com_SetBaud(COM1,960);

    com_Init(combuf, 48, 0); // set up a comms circular buffer, use the entire buffer, no sync character

    repeat

    pokeW(TIMER0, 2000); // set delay so we stay in next loop for 5 seconds

    // wait for a while gathering bytes
    // and continuously displaying the count
    // of characters in the buffer.
    repeat
    // Video1 1.0 generated 16/11/2013 18:32:51

    // txt_MoveCursor(2,1); // reset cursor to line 3, column 2
    // print("Buffered ", [DEC2Z] ( com_Count() )); // show count of chars in buffer


    until (!peekW(TIMER0)); // loop until TIME_OUT register is 0
    /*
    if (com_Full())
    txt_MoveCursor(3,1); // reset cursor to line 5, column 2
    print("Buffer Full ", (++e) ); // print error count
    endif

    if (com_Error())
    txt_MoveCursor(4,1); // reset cursor to line 7, column 2
    print("Comms Error ", (++e2) ); // print error count
    endif
    */
    // now dump whatever we got to the terminal
    while ( (char := serin()) >= 0)
    // txt_Set(TEXT_COLOUR, RED);
    gfx_MoveTo(20,44);
    // print("\n'",[CHR]char,"' is ");
    to(COM1); putch(char); // send buffered chars to com port
    //wend


    switch
    /*
    case (char == 'M')
    redo := 20;
    page += dir ;

    if (page < 0)
    page := 0 ;
    else if (page >= Strings1Count)
    page := Strings1Count-1 ;
    else

    // Strings1 1.0 generated 05/01/2014 14:03:00
    // while (redo--)
    colr:=RAND();pause(700);

    // Strings4 1.0 generated 25/02/2014 10:32:40
    //// media_SetSector(0, Strings2FontStartL) ; // must come b4 setting fontID
    //// txt_FontID(MEDIA) ; // Font index correct at time of code generation
    txt_FGcolour(colr) ;
    txt_BGcolour(BLACK) ;
    gfx_MoveTo(0 , 4) ;
    PrintDisk(Strings4StartH, Strings4StartL, Strings4Size, page) ; // where i is Message 0 - Strings4Count-1


    // wend
    endif
    */

    case (char == 'A')

    // Image2 1.0 generated 22/08/2014 09:47:02
    img_Show(hndl,iImage2) ;

    pause(7000);
    case (char == 'B')


    // Image3 1.0 generated 22/08/2014 09:47:16
    img_Show(hndl,iImage3) ;

    pause(7000);
    // putstr(" THREE");
    // com_Init(combuffer, 2, 0); // reset buffer

    case (char == 'C')


    // Image4 1.0 generated 22/08/2014 09:47:47
    img_Show(hndl,iImage4) ;

    media_Image(0, 3) ; // show image

    case (char == 'D')

    for (frame := 0; frame <= 47; frame++)

    // Video3 1.0 generated 22/08/2014 09:48:06
    img_SetWord(hndl, iVideo3, IMAGE_INDEX, frame) ; // where frame is 0 to 47
    img_Show(hndl,iVideo3) ;

    pause(1);
    next
    pause(7000);



    case (char == 'P')

    gfx_Cls() ;


    default:

    endswitch

    wend
    pause(1000);


    until ( com_Full() || com_Error() ); // reset if error occurred




    endfunc

    ===================================================================================================

    Thanks,
    Eyall

  • #2
    The main issue with your code is:-
    pokeW(TIMER0, 2000); // set delay so we stay in next loop for 5 seconds
    repeat
    until (!peekW(TIMER0)); // loop until TIME_OUT register is 0
    This is the Goldelox way of handling timers.

    For Picaso you should have something like:-
    sys_SetTimer(TIMER0, 2000); // set delay so we stay in next loop for 5 seconds
    repeat
    until (!sys_GetTimer(TIMER0)); // loop until TIME_OUT register is 0
    Mark

    Comment

    Working...
    X