- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
#include <avr/io.h>
#include <util/delay.h>
#define BAUDRATE 115200
#define BAUD_PRESCALLER (((F_CPU / (BAUDRATE * 16UL))) - 1)
//Declaration of our functions
void USART_init(void);
unsigned char USART_receive(void);
void USART_send( unsigned char data);
int main(void){
USART_init(); //Call the USART initialization code
while(1){ //Infinite loop
USART_send('A');
_delay_ms(1000); //Delay for 5 seconds so it will re-send the string every 5 seconds
}
return 0;
}
void USART_init(void){
UBRR1H = (uint8_t)(BAUD_PRESCALLER>>8);
UBRR1L = (uint8_t)(BAUD_PRESCALLER);
UCSR1B = (1<<RXEN1)|(1<<TXEN1);
UCSR1C = (3<<UCSZ10);
}
unsigned char USART_receive(void){
while(!(UCSR1A & (1<<RXC1)));
return UDR1;
}
void USART_send( unsigned char data){
while(!(UCSR1A & (1<<UDRE1)));
UDR1 = data;
}
Ubuntu 上的 minicom 设置为 115200 8N1
我正在使用通信端口的 Elegoo ATMEGA2560、TX1 和 RX1 以及 GND 引脚。 https://github.com/enthusiasticgeek/Elegoo_Mega_2560
我打算从 ATMEGA 发送“A”,并希望在 PC 上的 minicom 上看到它。但我在 minicom 上收到“_”。我将 minicom 设置更改为 115200 7N1,但仍然收到“_”。然后我更改为 115200 6N1 然后我得到一个不同的二进制字符。我尝试更改 minicom 设置但无济于事。知道我出了什么问题吗?
这就是我发送不同字符时看到的结果。
预期(AVR 发送) ASCII 0x56 [01010110] (V)
观察到(PC 接收) ASCII 0x2A [00101010] (*)
预期(AVR 发送) ASCII 0x41 [01000001] (A)
观察到(PC 接收) ASCII 0x5F [01011111] (_)
预期(AVR 发送) ASCII 0x42 [01000010] (B)
观察到(PC 接收) ASCII 0x2F [00101111] (/)
预期(AVR 发送) ASCII 0x55 [01010101] (U)
观察到(PC 接收) ASCII 0x55 [01010101] (U)
这是我的 fuse 设置 https://github.com/enthusiasticgeek/Elegoo_Mega_2560/blob/master/avrdude.conf
memory "lfuse"
size = 1;
write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0",
"x x x x x x x x i i i i i i i i";
read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0",
"x x x x x x x x o o o o o o o o";
min_write_delay = 9000;
max_write_delay = 9000;
;
memory "hfuse"
size = 1;
write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0",
"x x x x x x x x i i i i i i i i";
read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0",
"x x x x x x x x o o o o o o o o";
min_write_delay = 9000;
max_write_delay = 9000;
;
memory "efuse"
size = 1;
write = "1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0",
"x x x x x x x x x x x x x i i i";
read = "0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0",
"x x x x x x x x o o o o o o o o";
min_write_delay = 9000;
max_write_delay = 9000;
;
这是我加载固件时发生的情况
avr-gcc -Os -DF_CPU=16000000UL -mmcu=atmega2560 -c -o test.o test.c
avr-gcc -mmcu=atmega2560 test.o -o test
#EEPROM
#avr-objcopy -O ihex -R .eeprom test test.hex
#FLASH
avr-objcopy -O ihex -R .flash test test.hex
sudo avrdude -c wiring -p m2560 -P /dev/ttyACM0 -b 115200 -V -U flash:w:test.hex -D
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.01s
avrdude: Device signature = 0x1e9801 (probably m2560)
avrdude: reading input file "test.hex"
avrdude: input file test.hex auto detected as Intel Hex
avrdude: writing flash (366 bytes):
Writing | ################################################## | 100% 0.08s
avrdude: 366 bytes of flash written
avrdude: safemode: Fuses OK (E:FD, H:D8, L:FF)
avrdude done. Thank you.
注意:我使用的是 CP-US-03 串行适配器,我认为它有 FTD232 芯片。我还使用代码从 Arduino 草图中得到了相同的结果
void setup() {
// initialize both serial ports:
Serial1.begin(115200);
}
void loop() {
// read from port 1, send to port 0:
//if (Serial1.available()) {
// int inByte = Serial1.read();
// Serial.write(inByte);
//
}
// read from port 0, send to port 1:
//if (Serial1.available()) {
int inByte = 0x41;//Serial.read();
Serial1.write(inByte);
delay(1000);
//}
}
因此,现在我开始看看这是否是TTL或逻辑电平转换问题。
最佳答案
事实证明这个问题与我的代码无关。我最终订购了以下 USB 2.0 转 TTL UART 6PIN CP2102 模块串行转换器,一切都非常顺利。
https://www.amazon.com/gp/product/B01LRVQIFQ/ref=oh_aui_detailpage_o01_s00?ie=UTF8&psc=1
常规 USB 转串口 CP-US-03 不起作用。
关于c - ATMEGA 2560 uart 代码未在 minicom 上给出正确的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45666084/
是否有一种简单的方法可以在软件中桥接 2 个 U(S)ART 线(STM32F107 上的 USART1 和 UART5)? 我需要将 USART1 上传入的数据转发到 UART5 并返回。 当前MC
我有这个疑问是因为,我知道 u-boot 有 uart 驱动程序,它有助于在启动内核时从 u-boot 开始查看调试日志(内核驱动程序不会在其中运行),我的问题是 在 u-boot 将控制权移交给内核
我正在为 Linux 上的 ARM AT91SAM9260 板编写 RS485 驱动程序。 当我初始化 UART 时,RTS 信号线变高 (1)。我想这会而且应该是 RS232 操作模式下的标准行为。
我有通过中断读取 USCI (UART) 的代码“正常”,但 TI SimpliciTI 堆栈是一个 CPU pig ,它在为 radio 提供服务时会丢弃 UART 字节。 我认为 DMA 是可行的
我的脑子被炸了,所以我想我会把这个传给社区。 当向我的嵌入式系统发送 1 个字符时,它始终认为它接收了 2 个字符。第一个接收到的字符似乎映射到传输的字符(以某种未知的方式),而第二个接收到的字符始终
我正在使用与 xbee 连接的 STM32f4 发现板从远程温度传感器接收温度数据。使用的代码是 CMIS UART 示例代码。我将接收数据包数据,一次 1 个字节。换句话说,每当接收到每个字节时,都
我在将串行设备连接到我正在为其编写代码的嵌入式设备时遇到问题。 我正在编写的设备有两个串行端口,一个来 self 的笔记本电脑的输入端口,一个输出到外部设备的端口。 当我将两个终端连接到笔记本电脑并查
您好,我正在学习如何通过 Nios 中的中断来使用 Uart,但我不知道如何开始。我已经在轮询中做到了,但我不知道如何开始使用中断。 如有任何帮助,我们将不胜感激 这是我的代码 #include
在我的代码中,我有一个在事件(接收)发生时触发的串行中断。在那里,我将数据保存到缓冲区,然后发送缓冲区进行分析。我遇到的问题是,我如何才能从串行端口获取整个响应以同时缓冲而不只是一个字符? Seria
我正在为开发板 (Beagle Bone Black) 开发一个应用程序,它将通过 UART 外围设备发送一些数据。开发板运行Linux Kernel(部分Debian发行版,3.8.x Linux
我尝试使用 C 程序在 Linux 环境中读取 UART 设备,但在使用屏幕与 UART 通信方面我遇到了不同的结果。 我用来测试UART通信的C代码如下: #include #include #
是否有可能以某种方式返回到页面的开头,而不是行、页。显然,使用 "hello\r" 之类的东西会写“hello”并返回到行的开头。 但是当我在第二行时呢?所以在 "hello\n" 之后它会让我进入第
所以我是新手,正在尝试了解寄存器和 UART,并已获得以下代码进行研究。 #include typedef volatile struct { uint32_t DR; uint32
我正在尝试编写一个函数来读取通过 UART 发送的一大块数据。我正在使用在 RaspberryPi 模型 B 上运行的 Raspbian Jessie,但我想在 openwrt 上使用此 C 代码(进
我正在尝试通过 UART 在两个 Linux 系统之间进行通信。我想发送大块数据。使用指定的波特率,它应该需要大约 5 秒,但它花费的时间几乎是预期时间的 10 倍。 由于我发送的内容超出了缓冲区一次
我想修改我的 linux 内核 (2.6.32) 的 UART 驱动程序。我正在为 ttyS2 使用标准的 uart 驱动程序我不知道确切的文件。问题很简单,在传输期间设置并保持 gpio 引脚为高电
我的问题是:通过 UART 或 SPI 驱动蓝牙模块(例如 BTM-331)的最佳方法是什么?我在以下上下文中问这个问题。我有一些连接到 uP 的模拟传感器。 uP 通过 spi 将此数据发送到另一个
在设备文件树上listed here我们可以看到一个 UART 设备: uarta: serial@70006000 { compatible = "nvidia,tegra210-uart"
试图为 STM32F4 UART 推出我自己的代码。 该芯片的一个特点是,如果您像 GNAT 编译器那样使用字节寻址来设置单个位,则半字的另一个字节中的相应位将被设置。数据表说使用半字寻址。有没有办法
我参与了一个项目,我需要从设备中提取一些数据并将其显示在 PC 上进行检查。我从中接收数据的设备发送一个字符串,其中包括设备 ID、当前模式、温度读数和电池读数。为方便起见,它们用逗号分隔。一个字符串
我是一名优秀的程序员,十分优秀!