本文介绍了串口PC到avr问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好! 



我需要使用Visual C ++将数据发送到我的Atmega256rfr2 xplained pro。  ;



问题是视觉c ++应该是正确的因为它适用于我的arduino。此外,avr代码应该是
是正确的,因为当我使用超级终端写入它时它会起作用。 

如果
有人可以告诉我这里出了什么问题我真的很感激。 

这是我的visual c ++代码(部分内容)

this->serialPort1 = (gcnew System::IO::Ports::SerialPort(this->components)); 

//open serial port 
if(!this->serialPort1->IsOpen){ 
   this->serialPort1->PortName=this->comboBox1->Text; 
   this->serialPort1->BaudRate=Int32::Parse(this->comboBox2->Text); 
   this->serialPort1->WriteTimeout = 500; 
   this->serialPort1->Open(); 
         } 
//send data 
if(this->serialPort1->IsOpen) 
 try { 
         this->serialPort1->WriteLine("a");} 
    catch(TimeoutException ^) 
    { 
         Ventanaemergente^ error = gcnew Ventanaemergente(); 
         error->label1->Text = "Time Out Exception"; 
         error->ShowDialog(); 
    } 

这是avr代码, 

atmega led应该在收到数据时闪烁 

And this is the avr code, 
atmega led should blink when data is received 

#include <avr/io.h> 
#include <util/delay.h> 

#define BAUD 9600 
#define MYUBRR (F_CPU/16/BAUD-1) 

int main(void) 
{ 
   UBRR1H = (unsigned char)(MYUBRR >> 8); 
   UBRR1L = (unsigned char) MYUBRR; 
   /* Enable receiver and transmitter */ 
   UCSR1B = (1<<RXEN1)|(1<<TXEN1); 
   /* Set frame format: 8data, 1stop bit */ 
   UCSR1C = (3<<UCSZ10); 
        /* configure led */ 
   DDRB |= (1 << 4); 
   PORTB |= (1 << 4); 

    while(1) 
    { 

    char ReceivedByte; 
    while (!(UCSR1A & (1 << RXC1))); 
    ReceivedByte = UDR1; 
   PORTB &= ~(1 << 4); 
   _delay_ms(1000); 
   PORTB |= (1 << 4); 
   _delay_ms(1000); 
   } 
} 


推荐答案

谢谢对于你的帖子。

你的问题超出VS一般问题论坛的支持范围,该论坛主要讨论Visual Studio IDE的使用问题,例如
WPF& SL设计师,Visual Studio Guidance Automation Toolkit,开发人员文档和帮助系统
Visual Studio编辑器。

Your issue is out of support range of VS General Question forum which mainly discusses the usage issue of Visual Studio IDE such asWPF & SL designer, Visual Studio Guidance Automation Toolkit, Developer Documentation and Help Systemand Visual Studio Editor.

如果你的问题出现在C ++代码中,那么你可以在Visual C ++论坛上咨询:

如果问题发生在连接处或者avr代码,我不知道哪个论坛可以支持这样的问题。所以
我正在将你的问题转移到主持人论坛("论坛在哪里??")。论坛的所有者将引导您进入正确的论坛。

If the issue occurred at the connection or the avr code, I don’t know which forum can support such issue. SoI am moving your question to the moderator forum ("Where is the forum for..?"). The owner of the forum will direct you to a right forum.

致以最诚挚的问候,


这篇关于串口PC到avr问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 01:26