Hit a wall using UART
hello,
as part of project, i've been trying make uart work between arduino due , arduino nano, have problem , don't know is. programs in c.
some characters transmitted correctly , not, looped through of them. have no interface on nano, did sending every character nano , echoing back.
here results:
- 64 out of 256 characters miscommunicated,
- sent characters, returned different, had 2 bits in common - here's mask: xxx00xxx,
- received characters, returned different, had 3 bits in common: xx110xxx
not forget, confident due not problem, since tested on own too. wired tx rx , aced test. plus checked what's happening on oscilloscope , due's transmission correct, whereas nano's wrong.
edit: oh , during test oscilloscope (transmitted 1 character) made led light mirror value of 1 of bits , turns out data on nano wrong it's read.
now, 1 thing note due works @ 3.3 v whereas nano @ 5 v. however, if i'm not mistaken should work fine simple voltage divider. due's tx connected directly nano's rx, , nano's tx divided 2 resistors , connected due's rx. said, haven't detected problems this. though think should try converting 3.3 v 5 v in case.
lastly, code:
due initialisation
due functions (i used nano_wc test)
nano
so, ideas?
as part of project, i've been trying make uart work between arduino due , arduino nano, have problem , don't know is. programs in c.
some characters transmitted correctly , not, looped through of them. have no interface on nano, did sending every character nano , echoing back.
here results:
- 64 out of 256 characters miscommunicated,
- sent characters, returned different, had 2 bits in common - here's mask: xxx00xxx,
- received characters, returned different, had 3 bits in common: xx110xxx
not forget, confident due not problem, since tested on own too. wired tx rx , aced test. plus checked what's happening on oscilloscope , due's transmission correct, whereas nano's wrong.
edit: oh , during test oscilloscope (transmitted 1 character) made led light mirror value of 1 of bits , turns out data on nano wrong it's read.
now, 1 thing note due works @ 3.3 v whereas nano @ 5 v. however, if i'm not mistaken should work fine simple voltage divider. due's tx connected directly nano's rx, , nano's tx divided 2 resistors , connected due's rx. said, haven't detected problems this. though think should try converting 3.3 v 5 v in case.
lastly, code:
due initialisation
code: [select]
pio_set_peripheral(pioa, pio_periph_a, pio_pa10a_rxd0 | pio_pa11a_txd0);
pio_pull_up(pioa, pio_pa10a_rxd0, 0);
pio_pull_up(pioa, pio_pa11a_txd0, pio_pullup);
sysclk_enable_peripheral_clock(id_usart0);
sam_usart_opt_t usart_opts = {
.baudrate = nano_baud,
.char_length = us_mr_chrl_8_bit,
.parity_type = us_mr_par_no,
.stop_bits = us_mr_nbstop_1_bit,
.channel_mode = us_mr_chmode_normal
};
usart_init_rs232(usart0, &usart_opts, sysclk_get_main_hz());
usart_enable_tx(usart0);
usart_enable_rx(usart0);
due functions (i used nano_wc test)
code: [select]
/*
blocking
write character usart0
*/
void nano_wc(uint8_t c) {
while(usart_write(usart0, (uint32_t)c));
}
/*
blocking
write string usart0
*/
void nano_ws(const char* s) {
while(*s) {
while(usart_write(usart0, (uint32_t)(*s)));
s++;
}
}
/*
blocking
read character usart0
returns 0 if no error has occurred
*/
uint32_t nano_rc(uint8_t* c) {
uint32_t cc;
while(usart_read(usart0, &cc));
*c = (uint8_t)(cc & 0xff);
return usart_get_status(usart0) & 0x60;
}
nano
code: [select]
#include <avr/io.h>
#include <avr/interrupt.h>
isr(usart_rx_vect) {
unsigned char data = udr0;
while(!(ucsr0a & (1<<udre0)));
udr0 = data;
}
int main(void) {
cli();
ubrr0h = 0;
ubrr0l = 3;
ucsr0b = (1<<rxen0)|(1<<txen0)|(1<<rxcie0);
ucsr0c = 3<<ucsz00;
sei();
while(1);
return 0;
}
so, ideas?
quote
- 64 out of 256 characters miscommunicated,how did arrive @ 256 characters? character on arduino signed variable, range of values -128 127. there no character definitions have negative values, there 128 possible values represent printable or non-printable characters.
Arduino Forum > Using Arduino > Networking, Protocols, and Devices (Moderator: fabioc84) > Hit a wall using UART
arduino
Comments
Post a Comment