Page 2 of 2

Re: Sample project with Uart on startkit

Posted: Mon Feb 24, 2020 1:45 pm
by Schatz143
Hi there!
I think it is this kind i am looking for but
I have
1)Xcore 200 explorer kit 2)FTDI USB to RS-232-PCB converter 3)Serial terminal tera term .
Would like to establish serial communication and intern use serial terminal via comports.
First step is to send and receive a byte via usb to rs 232 and to use COM PORT and possibly check it on oscilloscope.
I am trying to find the best possible way to move ahead.I was taking noteS from SPI MASTER AND SPI SLAVE Component examples but they werent really into communicating through usb to rs 232 convereter.Any help would be appreciated in moving forward.Thanks

Re: Sample project with Uart on startkit

Posted: Mon Feb 24, 2020 2:45 pm
by mon2
See the attached document which is similar to your request. In short, you will use 2 port pins, one for TX and the other for RX. Apply an external rs232 transceiver and this IP. Use your ftdi dongle to mate to the rs232 xcvr.


Multi-Uart-Com-Port-Demo-Quickstart-Guide-_documentation_1.0.0rc1.a.pdf

Re: Sample project with Uart on startkit

Posted: Tue Feb 25, 2020 1:18 pm
by Schatz143
Hi there!
is there any sample example to run in x200 explorer kit? All i see for slice kit.
a simple code to send and recive a byte on this kit could be good to undertsand how it works.
would be glad if anybody can post some code as an example.Thanks.
All i need is justo send and recieve a byte over Tx Rx and see on the osciloscope and to use tera term
it might be easy to some but not for me.Any help is much needed to understand.

Re: Sample project with Uart on startkit

Posted: Tue Feb 25, 2020 2:32 pm
by mon2
XC-1A-Tutorial_X3948A.pdf

Hi. A bit swamped right now but to get you started, review the attached document, Section 4. Follow this example but select for your target, the xcore-200 explorer kit. Review the kit hardware manual and select any 1 bit port you can probe. This will be any port with a number 1 in the port name denoting 1 bit width. Use that port label in the source code and this code should yield a tx uart IP block framing @ 115.2k but at CMOS level. You can then monitor with a scope it run in the simulator. Call this tx routine in a permanent loop to monitor the results. Please post your results.

Re: Sample project with Uart on startkit

Posted: Wed Feb 26, 2020 6:52 am
by Schatz143
Hi mon2!
this one terminates faster and cannot see any at 1H port (D23).i tried keeping in permanent loop and got an error.would you check?

Code: Select all

# include <xs1.h>
# define BIT_RATE 115200
# define BIT_TIME XS1_TIMER_HZ / BIT_RATE
out port TXD = XS1_PORT_1H ;//D23 pin
int main ()
{

return 0;
}

 void txByte(out port TXD,int byte)
    {

        unsigned time;
        timer t;
        t:>time;
        TXD <: 0;
        time += BIT_TIME ;
        t when timerafter ( time ) :> void ;
        
        for ( int i =0; i <8; i ++)
        {
        TXD <: >> byte ;
        time += BIT_TIME ;
        t when timerafter ( time ) :> void ;
        }
        TXD <: 1;
        time += BIT_TIME ;
        t when timerafter ( time ) :> void ;
        }



Re: Sample project with Uart on startkit

Posted: Wed Feb 26, 2020 8:20 am
by mon2
Try the following (revised) code:

Code: Select all

/*
 * Full_UART.xc
 *
 *  Created on: Feb 27, 2020
 *      Author: kumar (Mon2)
 *
 *     UART Receiver by Leon Heller
 *     https://www.xcore.com/viewtopic.php?f=21&t=5263
 *
 */


#include <xs1.h>
#define BIT_RATE 115200
#define BIT_TIME XS1_TIMER_HZ / BIT_RATE
out port TXD = XS1_PORT_1H ; //D23 pin
in port  RXD = XS1_PORT_1G ; //D22 pin


void txByte(unsigned int byte)
   {

       unsigned time;
       timer t;
       t:>time;
       TXD <: 0;
       time += BIT_TIME ;
       t when timerafter ( time ) :> void ;

       for ( int i =0; i <8; i ++)
       {
       TXD <: >> byte ;
       time += BIT_TIME ;
       t when timerafter ( time ) :> void ;
       }
       TXD <: 1;
       time += BIT_TIME ;
       t when timerafter ( time ) :> void ;
       }


unsigned char rxByte(void)
{
   unsigned data = 0, time;
   int i;
   unsigned char c;


   // wait for start bit
   RXD when pinseq (0) :> int _ @ time;
   time += BIT_TIME + (BIT_TIME >> 1);

   // sample each bit in the middle.
   for (i = 0; i < 8; i += 1)
   {
      RXD @ time :> >> data;
      time += BIT_TIME;
   }

   // reshuffle the data.
   c = (unsigned char) (data >> 24);

   return {c};
}


int main ()
{
unsigned int c;

while(1) // perm loop
{
txByte('\r');
txByte('\n');

for (c='a';c<'z';c++)
   txByte(c);
}

// receive a byte from outside world
c = rxByte();

// transmit the received byte over UART
txByte(c);

return 0;
}


17:58:54 **** Incremental Build of configuration Default for project UART_Test ****
xmake CONFIG=Default all
Checking build modules
No build modules used.
Analyzing UART_Test.xc
Rebuild .build/_pca.rsp
Propagating analysis
Creating dependencies for UART_Test.xc
Compiling UART_Test.xc
Rebuild .build/_obj.rsp
Creating UART_Test.xe
Build Complete

17:58:57 Build Finished (took 3s.168ms)

Re: Sample project with Uart on startkit

Posted: Wed Feb 26, 2020 11:50 am
by Schatz143
there is compilation error


^

Re: Sample project with Uart on startkit

Posted: Thu Feb 27, 2020 12:02 am
by mon2
try the above (revised) code - the original version was posted @ 3AM with one eye open and it shows :) Have not tested this code but it does compile ok on my PC.

Re: Sample project with Uart on startkit

Posted: Thu Feb 27, 2020 10:06 am
by Schatz143
Hi mon2!
Thanks for the support .
no error for transmiting but it would be better to have both TXD AND RXD to check in the serial emulator but seriously no idea to how to include RXD factor in this code.Would be happy to know.

Re: Sample project with Uart on startkit

Posted: Fri Feb 28, 2020 3:22 am
by mon2
Hi. Try the latest version - not tested but compiles fine and 'should work' as advertised. Feel free to change the TXD / RXD port pins to suit - just be sure to use a single bit port pin for the immediate code.