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

Post 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


View Solution
User avatar
mon2
XCore Legend
Posts: 1913
Joined: Thu Jun 10, 2010 11:43 am
Contact:

Post 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.


Schatz143
Member++
Posts: 31
Joined: Mon Jan 20, 2020 9:54 am

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

Post by mon2 »

XC-1A-Tutorial_X3948A.pdf
(822.81 KiB) Downloaded 257 times
XC-1A-Tutorial_X3948A.pdf
(822.81 KiB) Downloaded 257 times

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

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


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

Post 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)
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

Post by Schatz143 »

there is compilation error


^
Attachments
error.png
(24.8 KiB) Not downloaded yet
error.png
(24.8 KiB) Not downloaded yet
User avatar
mon2
XCore Legend
Posts: 1913
Joined: Thu Jun 10, 2010 11:43 am
Contact:

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

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

Post 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.
Post Reply