Sample project with Uart on startkit Topic is solved

New to XMOS and XCore? Get started here.
Schatz143
Member++
Posts: 31
Joined: Mon Jan 20, 2020 9:54 am

Re: Sample project with Uart on startkit

Postby Schatz143 » Mon Feb 24, 2020 1:45 pm

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
View Solution
User avatar
mon2
XCore Legend
Posts: 1679
Joined: Thu Jun 10, 2010 11:43 am

Postby mon2 » Mon Feb 24, 2020 2:45 pm

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
You do not have the required permissions to view the files attached to this post.
Schatz143
Member++
Posts: 31
Joined: Mon Jan 20, 2020 9:54 am

Postby Schatz143 » Tue Feb 25, 2020 1:18 pm

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.
User avatar
mon2
XCore Legend
Posts: 1679
Joined: Thu Jun 10, 2010 11:43 am

Postby mon2 » Tue Feb 25, 2020 2:32 pm

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.
You do not have the required permissions to view the files attached to this post.
Schatz143
Member++
Posts: 31
Joined: Mon Jan 20, 2020 9:54 am

Postby Schatz143 » Wed Feb 26, 2020 6:52 am

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 ;
        }


User avatar
mon2
XCore Legend
Posts: 1679
Joined: Thu Jun 10, 2010 11:43 am

Postby mon2 » Wed Feb 26, 2020 8:20 am

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)
Last edited by mon2 on Fri Feb 28, 2020 3:21 am, edited 2 times in total.
Schatz143
Member++
Posts: 31
Joined: Mon Jan 20, 2020 9:54 am

Postby Schatz143 » Wed Feb 26, 2020 11:50 am

there is compilation error


^
You do not have the required permissions to view the files attached to this post.
User avatar
mon2
XCore Legend
Posts: 1679
Joined: Thu Jun 10, 2010 11:43 am

Postby mon2 » Thu Feb 27, 2020 12:02 am

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.
Schatz143
Member++
Posts: 31
Joined: Mon Jan 20, 2020 9:54 am

Postby Schatz143 » Thu Feb 27, 2020 10:06 am

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.
User avatar
mon2
XCore Legend
Posts: 1679
Joined: Thu Jun 10, 2010 11:43 am

Postby mon2 » Fri Feb 28, 2020 3:22 am

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.

Who is online

Users browsing this forum: No registered users and 2 guests