Hi. You have many options but agree there may not be a complete public project using the StartKit & UART components.
From past reviews, we did manage to create a bit banged UART without an external crystal / clock source that could frame fine with PC baud rates. Keep in mind that the XMOS cores are ultra fast GPIO ports. Only thing faster is to skip to FPGA devices. So keeping this in mind one idea to explore is:
1) configure your FTDI controller so that you are working only with the CMOS (3v3) levels. NO RS232 unless you have a RS232 transceiver on the XMOS port pins as well. You will kill the XMOS CPU if are not careful !!
2) Connect any free single bit port (tons on J7 of your kit) -> wire that to the FTDI UART RX (again direct = 3v3 levels and NOT RS232). If you have RS232 then you must find a way to disable or source another FTDI board or apply a RS232 transceiver onto the XMOS. Recommend you stick with CMOS to CMOS interfacing at this time. Connect a common ground between XMOS board and your FTDI cable.
3) Now, write a simple single thread piece of code to output to the selected port pin -> UART basics = STAR BIT + delay + 8 data bits (delay between each bit) + stop bit. Send out the single character "A" using this logic. Keep tweaking your delays till you can see "A" on the FTDI tool with a terminal program. XMOS has precision delays which can be dialed up to frame @ 115200 bps, etc. We recall doing this for even faster rates.
The XMOS UART libraries are doing the same thing but often you do not need the extra fat of such software IP. It is a great learning method to test the code as posted above. Search around for "BIT BANG UART" to understand what needs to be done in the s/w. Time permitting, can post some code over the next few days but will not have access to lab instruments till Monday.
The XMOS tools allow to create a s/w oscilloscope to monitor the details of the selected single port pin, etc. or you can even connect a simple LED with a current limit resistor to 3v3 OR use a meter to check on your work. Start with:
Code: Select all
your_port_pin <: 1; // force the port pin to be a "1"
while(1);
run the above and confirm your port pin is a "1" and then
Code: Select all
your_port_pin <: 0; // force the port pin to be a "0"
while(1);
run the above and confirm your port pin is a "0" and then
Code: Select all
#include <timer.h>
#define delay 1000
while(1)
{
your_port_pin <: 1; // force the port pin to be a "1"
delay_milliseconds(delay);
your_port_pin <: 0; // force the port pin to be a "0"
delay_milliseconds(delay);
}
and your port pin should now pulse @ 1 Hz. Expand your code using this idea and once the delay is matching say 9600 bps, you will indeed see the character you send from XMOS being framed on the FTDI tool.
Now all this pain goes away if you do source a compatible clock source and apply this external clock onto yet another free single bit port pin. Using this external clock, you can inform the XMOS code to spit out or read in bits based on the external clock edges. Compatible clock values are 1.8432 Mhz, 14.7456 Mhz, or multiples of.
well, well, have a look at this complete code posted here:
http://www.xcore.com/viewtopic.php?f=21&t=5263
Courtesy of Leon Heller but modded for your StartKit:
Code: Select all
#include <platform.h>
#define BIT_RATE 115200
#define BIT_TIME XS1_TIMER_HZ / BIT_RATE
void txByte(unsigned char);
unsigned char rxByte(void);
out port TXD = XS1_PORT_1F; // J7 connector Pin 1 on StartKit
in port RXD = XS1_PORT_1H; // J7 connector Pin 2 on StartKit
unsigned char array[10];
int main()
{
//unsigned char c;
int i;
while (1)
{
for (i = 0; i < 10; i++)
array[i] = rxByte();
for (i = 0; i < 10; i++)
txByte(array[i]);
}
return 0;
}
unsigned char rxByte(void)
{
unsigned data = 0, time;
int i;
unsigned char c;
// Wait for stop bit
RXD when pinseq (1) :> int _;
// 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};
}
void txByte(unsigned char c)
{
unsigned time, data;
data = c;
// get current time from port with force out.
TXD <: 1 @ time;
// Start bit.
TXD <: 0;
// Data bits.
for (int i = 0; i < 8; i += 1)
{
time += BIT_TIME;
TXD @ time <: >> data;
}
// two stop bits
time += BIT_TIME;
TXD @ time <: 1;
time += BIT_TIME;
TXD @ time <: 1;
}
You will need to customize the port pins using for example J7 row on the StartKit to map the TX & RX pins.
Study and do try this out @ 115200 bps and chime back if you have issues. Best to create an empty project with the StartKit as the target and then cut & paste the above source code into the empty project and compile. Connect your TX on XMOS to the CMOS FTDI RX; your RX on XMOS to the CMOS FTDI TX; common ground. Run a terminal program on your PC @ 115200 N81 framing. Then send out some character or text using this UART to test.