Hello everyone!
I wonder that if anyone have the experience on using uart.lib to code a program sampling data from RS232 port. The following are my codes:
/*
* Test_uart_rx_01.xc
*
* Created on:
* Author: mayue
*/
// Copyright (c) 2015, XMOS Ltd, All rights reserved
#include <xs1.h>
#include <platform.h>
#include <print.h>
#include <uart.h>
#include <stddef.h>
#include <stdio.h>
port p_uart_rx = on tile[0] : XS1_PORT_1I;
port p_uart_tx = on tile[0] : XS1_PORT_1K;
#define BAUD_RATE 115200
#define RX_BUFFER_SIZE 6
#define SEND_PERIOD 100000 // 1ms sending rate
/* This function performs the main "application" that outputs and reads
some bytes over UART */
void app_tx(client uart_tx_if uart_tx)
{
uint8_t byte;
timer t_send_timer;
unsigned int send_time;
t_send_timer :> send_time;
send_time += SEND_PERIOD;
printstrln("Test started");
byte = 0;
while(1)
{
select
{
case t_send_timer when timerafter(send_time) :> void:
{
uart_tx.write(byte++);
if (byte == 6)
byte = 0;
send_time += SEND_PERIOD;//Setup time for next send event
break;
}
}
}
}
void app_rx(client uart_rx_if uart_rx)
{
uint8_t data[6];
while(1)
{
select {
case uart_rx.data_ready():
{
{
data [0] = uart_rx.wait_for_data_and_read();
data [1] = uart_rx.wait_for_data_and_read();
data [2] = uart_rx.wait_for_data_and_read();
data [3] = uart_rx.wait_for_data_and_read();
data [4] = uart_rx.wait_for_data_and_read();
data [5] = uart_rx.wait_for_data_and_read();
printf("\n Data 0 is %d\n", data[0]);
printf("\n Data 1 is %d\n", data[1]);
printf("\n Data 2 is %d\n", data[2]);
printf("\n Data 3 is %d\n", data[3]);
printf("\n Data 4 is %d\n", data[4]);
printf("\n Data 5 is %d\n", data[5]);
}
break;
}
}
}
}
/* "main" function that sets up two uarts and the application */
int main() {
interface uart_rx_if i_rx;
interface uart_tx_if i_tx;
input_gpio_if i_gpio_rx[1];
output_gpio_if i_gpio_tx[1];
par {
on tile[0]: output_gpio(i_gpio_tx, 1, p_uart_tx, null);
on tile[0]: uart_tx(i_tx, null,
BAUD_RATE, UART_PARITY_NONE, 8, 1,
i_gpio_tx[0]);
on tile[0].core[0] : input_gpio_1bit_with_events(i_gpio_rx[0], p_uart_rx);
on tile[0].core[0] : uart_rx(i_rx, null, RX_BUFFER_SIZE,
BAUD_RATE, UART_PARITY_NONE, 8, 1,
i_gpio_rx[0]);
on tile[0]: app_tx(i_tx);
on tile[0]: app_rx(i_rx);
}
return 0;
}
In brief, there're two concurrent functions, app_tx sending data and app_rx receiving data. But the results below seems not good except the first round:
Test started
Data 0 is 0
Data 1 is 1
Data 2 is 2
Data 3 is 3
Data 4 is 4
Data 5 is 5
Data 0 is 0
Data 1 is 0
Data 2 is 0
Data 3 is 0
Data 4 is 65
Data 5 is 64
Data 0 is 0
Data 1 is 0
Data 2 is 0
Data 3 is 0
Data 4 is 64
Data 5 is 160
Data 0 is 0
Data 1 is 0
Data 2 is 0
Data 3 is 0
Data 4 is 32
Data 5 is 80
Data 0 is 0
Data 1 is 0
Data 2 is 0
Data 3 is 0
Data 4 is 65
Data 5 is 64
Data 0 is 0
Data 1 is 0
Data 2 is 0
Data 3 is 0
Data 4 is 64
Data 5 is 160
Data 0 is 0
Data 1 is 0
Data 2 is 0
Data 3 is 0
Data 4 is 32
Data 5 is 80
Data 0 is 0
Data 1 is 0
Data 2 is 0
Data 3 is 0
Data 4 is 65
Data 5 is 64
If anyone can find the cause of the issue?
Regards
Yue
XMOS UART ISSUE
-
- Junior Member
- Posts: 5
- Joined: Mon Aug 25, 2014 9:25 am
-
- Member++
- Posts: 24
- Joined: Thu Aug 14, 2014 10:55 am
I couldn't test code now. But i guess the issue would be the buffer overflow which happens while your print statements are still sending the data to the xTIMEcomposer. Can you please enable Xscope and run the application? And also please try to increase SEND_TIME to check whats happening.