I'm been also having some trouble with the simple uart module. I've modified the uart_back2back code so it would just listen to incoming transmission from a Arduino (simulating a sensor I would like to connect to the xmos)
Here the modified xmos code:
Code: Select all
// Copyright (c) 2011, XMOS Ltd, All rights reserved
// This software is freely distributable under a derivative of the
// University of Illinois/NCSA Open Source License posted in
// LICENSE.txt and at <http://github.xcore.com/>
#include <xs1.h>
#include <platform.h>
#include "uart_rx.h"
#include "uart_tx.h"
#include <print.h>
void forward(chanend uartTX, chanend uartRX)
{
uart_rx_client_state rxState;
unsigned char rcvbuffer[26];
unsigned char byte;
int i;
unsigned int gotest;
gotest=1;
byte=0;
uart_rx_init(uartRX, rxState);
while(gotest) {
// printstr("Echo : ");
for(i=0;i<13;i++) {
rcvbuffer[i] = uart_rx_get_byte(uartRX, rxState);
}
for(i=0;i<13;i++) {
printchar(rcvbuffer[i]);
}
//printstr(" done\n");
}
printstr("Test Completed\n");
}
//buffered in port:1 rx = on stdcore[0] : XS1_PORT_1A;
//out port tx = on stdcore[0] : XS1_PORT_1B;
buffered in port:1 rx = on stdcore[0] : XS1_PORT_1G;
out port tx = on stdcore[0] : XS1_PORT_1H;
#define BAUD_RATE 115200
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
#pragma unsafe arrays
int main() {
chan chanTX, chanRX;
par {
on stdcore[0] : {
unsigned char tx_buffer[64];
unsigned char rx_buffer[64];
tx <: 1;
printstr("Listening...\n");
par {
uart_rx(rx, rx_buffer, ARRAY_SIZE(rx_buffer), BAUD_RATE, 8, UART_TX_PARITY_NONE, 1, chanRX);
uart_tx(tx, tx_buffer, ARRAY_SIZE(tx_buffer), BAUD_RATE, 8, UART_TX_PARITY_NONE, 1, chanTX);
}
}
on stdcore[0] : {
forward(chanTX, chanRX);
}
}
return 0;
}
Code: Select all
void setup() {
Serial.begin(115200);
}
void loop() {
Serial.print("Hello World!\n");
// delay(5);
}
Thanks
Alex
(P.s. I moved this post from the other one since I felt It was in the wrong section)