No announcement yet.

serout problem

  • Filter
  • Time
  • Show
Clear All
new posts

  • serout problem


    The display uOLED-96 Tx and Rx is connected to my microcontroller.

    The display Rx is works fine, and what i'm sending from the microcontroller is what is see on the display.

    but something is wrong on the Tx (to the microcontroller), i cannot read correctly the serout.

    I'm sending '5' using "serout" syntax and got '.' or A or B in the microcontroller.

    I'v tried several buffer sizes.

    What can be the problem?

    The code:

    #platform "GOLDELOX" /* 4DGL Demo Application - Test Serial Echo - -- GOLDELOX Platform --*/ #inherit "4DGL_16bitColours.fnc" var combuf[24]; // 24 vars = 48 bytesvar combuffer[1]; // 24 vars = 48 bytes func main()var chr,char, e, e2; e := 0; e2 := 0; repeat gfx_Set(OUTLINE_COLOUR, DARKOLIVEGREEN); // set outline colour, gfx_Cls() will draw outline gfx_Cls(); 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 com_Init(combuf, 48, 0); // set up a comms circular buffer, use the entire buffer, no sync character repeat pokeW(TIMER0, 5000); // 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 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(COM0); putch(char); // send buffered chars to com port //wend gfx_MoveTo(10,44); switch case (char == '3') putstr(" THREE"); com_Init(combuffer, 2, 0); // reset buffer serout('5');//to(COM0); putch('5'); // break; case (char == '2') putstr(" TWO"); default: //putstr(" Idle"); endswitch wend pause(1000); until ( com_Full() || com_Error() ); // reset if error occurred forever endfunc

  • #2

    The buffer is only for serial input, so that should have nothing to do with it.

    What happens if you user the terminal utility supplied with Workshop, does that see the '5'?


    • #3

      Yes i see it in the terminal, forgot to tell you.

      therefore i dont undertsand what is wrong in the micro as it tx well.

      Attached files


      • #4

        No idea really, do you have a circuit of your micro and how it's connected?

        Also the init code for the comms?


        • #5


          The circuit is ok because i can communicate thru Terminal Tx/Rx.

          I'v added delay 3sec in the display before serout, and now it is ok as i have some delays in the uC code, then i missed the serout.

          Another question: why in the 4D terminal there is '3' before any other character (please look at the jpeg in my previous post), in regular terminal i didnt have it.



          • #6

            Another question: why in the 4D terminal there is '3' before any other character (please look at the jpeg in my previous post), in regular terminal i didnt have it.
            I presumed you did that, the first line shows a '3' going out(&gt, the second line shows it coming back (&ltand followed by the '5'.


            • #7

              Yes of course, but why i see '33' and no only '3' ?


              • #8

                The right hand window is in hex, the hex value of 3 is 33.

                The left hand window is ASCII