完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
我想从UART发送一个字符。问题是,在我的输出中,我只得到???????我使用的是DSPIC33 FJ64 GP206A,XC16和8MHZEL中的外部晶体是我的代码:我认为我的问题是ISU2BRG速度。
以上来自于百度翻译 以下为原文 I'm trying to send just a single character from uart. The problem is that in my output i get only ?????. I'm using DSPIC33FJ64GP206A, XC16 and External crystal in 8mhz Here is my code: #include #include #include #include #define _XTAL_FREQ 32000000 #define FOSC _XTAL_FREQ #define FCY _XTAL_FREQ/2 #define BAUDRATE 9600 #define myBAUDRATE (FCY/(16*BAUDRATE)) - 1 void WriteUart( char txData) { while (U1STAbits.UTXBF == 1); //wait until TXIF is set => TXBUF ready U2TXREG = txData; } void main(void) { OSCCON =0x3000; CLKDIV=0x3040; PLLFBD=0x30; OSCTUN=0x0000; while (_LOCK ==0); { } TRISFbits.TRISF5 = 0;//TX TRISFbits.TRISF6 = 1;//RX TRISGbits.TRISG1=0; //rs485 control pin LATGbits.LATG1=1; //rs485 set high for writing U2BRG = myBAUDRATE; U2STA = 0x0000; U2MODE = 0x0000; U2MODEbits.UARTEN = 1; //UARTx is enabled; UARTx pins are controlled by UARTx as defined by the UEN<1:0> and UTXEN control bits U2STAbits.UTXEN = 1; //UARTx transmitter enabled; UxTX pin is controlled by UARTx (if UARTEN = 1) U2MODEbits.PDSEL = 0; //01 = 8-bit data, even parity, 11 = 9-bit data, no parity IEC1bits.U2RXIE = 1;//Enable Interrupts while(1) { WriteUart("1"); } } #pragma config BWRP = WRPROTECT_OFF // Boot Segment Write Protect (Boot Segment may be written) #pragma config BSS = NO_FLASH // Boot Segment Program Flash Code Protection (No Boot program Flash segment) #pragma config RBS = NO_RAM // Boot Segment RAM Protection (No Boot RAM) // FSS #pragma config SWRP = WRPROTECT_OFF // Secure Segment Program Write Protect (Secure segment may be written) #pragma config SSS = NO_FLASH // Secure Segment Program Flash Code Protection (No Secure Segment) #pragma config RSS = NO_RAM // Secure Segment Data RAM Protection (No Secure RAM) // FGS #pragma config GWRP = OFF // General Code Segment Write Protect (User program memory is not write-protected) #pragma config GSS = OFF // General Segment Code Protection (User program memory is not code-protected) // FOSCSEL #pragma config FNOSC = PRIPLL // Oscillator Mode (Primary Oscillator (XT, HS, EC) w/ PLL) #pragma config IESO = ON // Two-speed Oscillator Start-Up Enable (Start up with FRC, then switch) // FOSC #pragma config POSCMD = XT // Primary Oscillator Source (XT Oscillator Mode) #pragma config OSCIOFNC = OFF // OSC2 Pin Function (OSC2 pin has clock out function) #pragma config FCKSM = CSDCMD // Clock Switching and Monitor (Both Clock Switching and Fail-Safe Clock Monitor are disabled) // FWDT #pragma config WDTPOST = PS32768 // Watchdog Timer Postscaler (1:32,768) #pragma config WDTPRE = PR128 // WDT Prescaler (1:128) #pragma config WINDIS = OFF // Watchdog Timer Window (Watchdog Timer in Non-Window mode) #pragma config FWDTEN = ON // Watchdog Timer Enable (Watchdog timer always enabled) // FPOR #pragma config FPWRT = PWR128 // POR Timer Value (128ms) // FICD #pragma config ICS = PGD1 // Comm Channel Select (Communicate on PGC1/EMUC1 and PGD1/EMUD1) #pragma config JTAGEN = OFF // JTAG Port Enable (JTAG is Disabled) I think that my problem is U2BRG speed |
|
相关推荐
11个回答
|
|
|
ChangetoRight,现在,您正在发送字符串地址的低字节。
以上来自于百度翻译 以下为原文 Change WriteUart("1"); to WriteUart('1'); Right now, you are sending the low byte of the address of the string. |
|
|
|
|
|
注意,这些问题应该在DSPIC3F主题论坛中,而不是在MPLABX论坛中,因为它们与IDE无关。
以上来自于百度翻译 以下为原文 Note, these questions should be in the dsPIC33F Topics forum, not here in the MPLABX forum, as they have nothing to do with the IDE. |
|
|
|
|
|
我改变了,但我把错误字符
以上来自于百度翻译 以下为原文 I change that but i'm taking wrong characters unspecified characters |
|
|
|
|
|
改为发送0x55,并观察范围内的TX引脚。(0x55=0B01010101,因此您将看到波特率的一半的方波)。
以上来自于百度翻译 以下为原文 Change it to send 0x55 instead, and observe the TX pin with a scope. (0x55 = 0b01010101, so you will see a square wave at half the baud rate). |
|
|
|
|
|
我也注意到,如果我只发送一次内,而它发送连续。OSCCon寄存器能影响我的读写吗?
以上来自于百度翻译 以下为原文 Also i noticed that if i will send only once inside while, it sends continuoesly. Can osccon registers influence my write and read? |
|
|
|
|
|
你把数据发送到哪里?个人电脑?检查你的GND连接。
以上来自于百度翻译 以下为原文 To where do you send your data ? PC ? Check your GND connection. |
|
|
|
|
|
转换到
以上来自于百度翻译 以下为原文 Change #pragma config FWDTEN = ON // Watchdog Timer Enable (Watchdog timer always enabled) to #pragma config FWDTEN = OFF // Watchdog Timer Disable |
|
|
|
|
|
是的,我正在向PC发送数据。我怎样才能检查我的OSCCon寄存器是正确的?我用PLL外晶体
以上来自于百度翻译 以下为原文 Yes i'm sending data to pc. How can i Check that my osccon registers are right? I'm using external crystal with pll bit 15 Unimplemented: Read as ‘0’ bit 14-12 COSC<2:0>: Current Oscillator Selection bits (read-only) 111 = Fast RC oscillator (FRC) with Divide-by-N 110 = Fast RC oscillator (FRC) with Divide-by-16 101 = Low-Power RC oscillator (LPRC) 100 = Secondary oscillator (Sosc) 011 = Primary oscillator (XT, HS, EC) with PLL 010 = Primary oscillator (XT, HS, EC) 001 = Fast RC Oscillator (FRC) with Divide-by-N and PLL (FRCDIVN + PLL) 000 = Fast RC oscillator (FRC) bit 11 Unimplemented: Read as ‘0’ bit bit 10-8 NOSC<2:0>: New Oscillator Selection bits(2) 111 = Fast RC oscillator (FRC) with Divide-by-N 110 = Fast RC oscillator (FRC) with Divide-by-16 101 = Low-Power RC oscillator (LPRC) 100 = Secondary oscillator (Sosc) 011 = Primary oscillator (XT, HS, EC) with PLL 010 = Primary oscillator (XT, HS, EC) 001 = Fast RC Oscillator (FRC) with Divide-by-N and PLL (FRCDIVN + PLL) 000 = Fast RC oscillator (FRC) bit 7 CLKLOCK: Clock Lock Enable bit 1 = If (FCKSM0 = 1), then clock and PLL configurations are locked If (FCKSM0 = 0), then clock and PLL configurations may be modified 0 = Clock and PLL selections are not locked, configurations may be modified bit 6 Unimplemented: Read as ‘0’ bit 5 LOCK: PLL Lock Status bit (read-only) 1 = Indicates that PLL is in lock, or PLL start-up timer is satisfied 0 = Indicates that PLL is out of lock, start-up timer is in progress or PLL is disabled bit4 Unimplemented: Read as ‘0’ bit 3 CF: Clock Fail Detect bit (read/clear by application) 1 = FSCM has detected clock failure 0 = FSCM has not detected clock failure bit 2 Unimplemented: Read as ‘0’ bit 1 LPOSCEN: Secondary (LP) Oscillator Enable bit 1 = Enable secondary oscillator 0 = Disable secondary oscillator bit 0 OSWEN: Oscillator Switch Enable bit 0 OSWEN: Oscillator Switch Enable bit 1= Request oscillator switch to selection specified by NOSC<2:0> bits 0 = Oscillator switch is complete |
|
|
|
|
|
你有范围吗?你似乎忽略了我的建议。
以上来自于百度翻译 以下为原文 Do you have a scope? You seem to have ignored my suggestions. |
|
|
|
|
|
你有范围吗?你似乎忽略了我的建议。对不起,我现在没有。@ QuiBi仍然缺少构建这方面的主要知识。这是你在PIC中设置的第一件事,让它起作用吗?例如,语法和一些主要的寄存器。我说的对吗?在数据表中,哪些是我需要设置的主要寄存器?系统控制寄存器映射?
以上来自于百度翻译 以下为原文 Do you have a scope? You seem to have ignored my suggestions. Sorry i dont have right now. @qɥb i'm still missing main knowledge for building this. Which is the first thing which you need to set in pic, to make it work? Example #pragma and some main registers. Am i right? In datasheet which is the main registers which i need to set? SYSTEM CONTROL REGISTER MAP? |
|
|
|
|
|
嗨,在你的程序中制作LED闪光灯代码,直到你了解振荡器、锁相环和计时器的工作原理。虽然LED闪烁可能看起来愚蠢的琐碎,但是LED闪光灯每秒钟精确地做一次闪光是一个合理的练习,并且重要的是检查频率和除法器的正确设置,以及功能。当你用示波器或逻辑分析仪来切换定时测量或诊断的I/O管脚时,基本上是相同的,只有一个更宽的频率范围可以观察到,直到振荡器和时序以一种你理解的方式工作,没有任何意义。搞乱UART通信。迈西尔
以上来自于百度翻译 以下为原文 Hi, Make LED flashing code in your program, until you understand how Oscillators, PLL and Timers work. While LED flashing may seem stupidly trivial, making a LED flash exactly once every second is a reasonable exercise, and important check that frequencies and dividers are set up correctly, and function the way you intend. It is essentially the same happening when toggling a I/O pin for timing measurements or diagnostics using oscilloscope or logic analyzer, there is just a wider range of frequencies possible to observe. Until oscillators and timing work in a way you understand, there is no point in messing with UART communication. Mysil |
|
|
|
|
只有小组成员才能发言,加入小组>>
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
473 浏览 0 评论
5793 浏览 9 评论
2334 浏览 8 评论
2224 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3530 浏览 3 评论
1124浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
1095浏览 1评论
我是Microchip 的代理商,有PIC16F1829T-I/SS 技术问题可以咨询我,微信:A-chip-Ti
873浏览 1评论
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
475浏览 0评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-2 04:11 , Processed in 3.620560 second(s), Total 97, Slave 79 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
1671