arm + serial + uart + monitor in visual c# -
**
solved: enabled property dtr of serial port component of visual studio. working fine. thank all.
**
i need help.
i wrote program in arm processor sends character 'a' through uart (usb). frequency 1 character/second. so, wrote program in visual c# receive character , show in text box. simple program.
the configurations of serial communications ok (baud_rate, stopbit, parity, data_bits)
the problem: cannot read character sent arm processor.
the facts:
1 - arm program working correctly in putty.
2 - visual c# program working correctly arduino board has same code arm has.
please guys, codes , if can, me.
this code of arm:
#include "inc/hw_ints.h" #include "inc/hw_memmap.h" #include "inc/hw_types.h" #include "driverlib/debug.h" #include "driverlib/gpio.h" #include "driverlib/interrupt.h" #include "driverlib/sysctl.h" #include "driverlib/uart.h" #include "drivers/rit128x96x4.h" //***************************************************************************** // //! \addtogroup example_list //! <h1>uart echo (uart_echo)</h1> //! //! example application utilizes uart echo text. first uart //! (connected ftdi virtual serial port on evaluation board) //! configured in 115,200 baud, 8-n-1 mode. characters received on //! uart transmitted uart. // //***************************************************************************** //***************************************************************************** // // error routine called if driver library encounters error. // //***************************************************************************** #ifdef debug void __error__(char *pcfilename, unsigned long ulline) { } #endif //***************************************************************************** // // uart interrupt handler. // //***************************************************************************** void uartinthandler(void) { unsigned long ulstatus; // // interrrupt status. // ulstatus = uartintstatus(uart0_base, true); // // clear asserted interrupts. // uartintclear(uart0_base, ulstatus); // // loop while there characters in receive fifo. // while(uartcharsavail(uart0_base)) { // // read next character uart , write uart. // //uartcharputnonblocking(uart0_base, uartchargetnonblocking(uart0_base)); uartcharputnonblocking(uart0_base,'a'); sysctldelay(16666666); //1.2 ms } } //***************************************************************************** // // send string uart. // //***************************************************************************** void uartsend(const unsigned char *pucbuffer, unsigned long ulcount) { // // loop while there more characters send. // while(ulcount--) { // // write next character uart. // uartcharputnonblocking(uart0_base, *pucbuffer++); } } //***************************************************************************** // // example demonstrates how send string of data uart. // //***************************************************************************** int main(void) { // // set clocking run directly crystal. // //sysctlclockset(sysctl_sysdiv_1 | sysctl_use_osc | sysctl_osc_main | sysctl_xtal_8mhz); sysctlclockset(sysctl_sysdiv_4 | sysctl_use_pll | sysctl_osc_main | sysctl_xtal_8mhz); // // initialize oled display , write status. // rit128x96x4init(1000000); rit128x96x4stringdraw("uart echo", 36, 0, 15); rit128x96x4stringdraw("port: uart 0", 12, 16, 15); rit128x96x4stringdraw("baud: 115,200 bps", 12, 24, 15); rit128x96x4stringdraw("data: 8 bit", 12, 32, 15); rit128x96x4stringdraw("parity: none", 12, 40, 15); rit128x96x4stringdraw("stop: 1 bit", 12, 48, 15); // // enable peripherals used example. // sysctlperipheralenable(sysctl_periph_uart0); sysctlperipheralenable(sysctl_periph_gpioa); // // enable processor interrupts. // intmasterenable(); // // set gpio a0 , a1 uart pins. // gpiopintypeuart(gpio_porta_base, gpio_pin_0 | gpio_pin_1); // // configure uart 115,200, 8-n-1 operation. // uartconfigsetexpclk(uart0_base, sysctlclockget(), 9600, (uart_config_wlen_8 | uart_config_stop_one | uart_config_par_none)); // // enable uart interrupt. // intenable(int_uart0); uartintenable(uart0_base, uart_int_rx | uart_int_rt); uartfifoenable(uart0_base); uartenable(uart0_base); // // prompt text entered. // uartsend((unsigned char *)"enter text: ", 12); // // loop forever echoing data through uart. // while(1) { } }
this visual c# code:
using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.threading.tasks; using system.windows.forms; using system.io.ports; namespace interfacearduinovs2013 { public partial class form1 : form { string rxstring; public form1() { initializecomponent(); timercom.enabled = true; } private void atualizalistacoms() { int i; bool quantdiferente; //flag para sinalizar que quantidade de portas mudou = 0; quantdiferente = false; //se quantidade de portas mudou if (combobox1.items.count == serialport.getportnames().length) { foreach (string s in serialport.getportnames()) { if (combobox1.items[i++].equals(s) == false) { quantdiferente = true; } } } else { quantdiferente = true; } //se não foi detectado diferença if (quantdiferente == false) { return; //retorna } //limpa combobox combobox1.items.clear(); //adiciona todas com diponíveis na lista foreach (string s in serialport.getportnames()) { combobox1.items.add(s); } //seleciona primeira posição da lista combobox1.selectedindex = 0; } private void timercom_tick(object sender, eventargs e) { atualizalistacoms(); } private void btconectar_click(object sender, eventargs e) { if (serialport1.isopen == false) { try { serialport1.portname = combobox1.items[combobox1.selectedindex].tostring(); serialport1.open(); } catch { return; } if (serialport1.isopen) { btconnect.text = "disconnect"; combobox1.enabled = false; } } else { try { serialport1.close(); combobox1.enabled = true; btconnect.text = "connect"; } catch { return; } } } private void form1_formclosed(object sender, formclosedeventargs e) { if(serialport1.isopen == true) // if port opened serialport1.close(); //close port } private void btenviar_click(object sender, eventargs e) { if(serialport1.isopen == true) serialport1.write(textboxsend.text); //send text in textbox rxstring = serialport1.readexisting(); messagebox.show(rxstring); } private void serialport1_datareceived(object sender, serialdatareceivedeventargs e) { rxstring = serialport1.readexisting(); //read data serial port messagebox.show(rxstring); this.invoke(new eventhandler(tratadadorecebido)); //call thread write data on textbox } private void tratadadorecebido(object sender, eventargs e) { textboxreceive.appendtext(rxstring); } } }
most have problem of baud rate. in c# code not see anywhere setting baud rate of com port. if 115200 print on arm board problem in arm board itself. printing 115,200 baud rate initializing arm board @ 9600 8n1
// // configure uart 115,200, 8-n-1 operation. // uartconfigsetexpclk(uart0_base, sysctlclockget(), 9600, (uart_config_wlen_8 | uart_config_stop_one | uart_config_par_none));
initialize corectly both ends of communication line before opening ports , try again. smaller baud rate on transmitter result in no characters printed on high speed configured receiver. on other hand, slow configured receiver(9600) capture garbage high speed transmitter.
Comments
Post a Comment