完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
如何在Explorer 16板中测试UART?我们使用PIC24F32KA304作为我们的PIM。我们试图在源代码中写一个已知的值,但问题是它没有出现在控制台(Putty/Teraterm)中。我们还使用CRO探测了TX引脚,并且它显示了这个值。请帮助我们也在控制台中得到它。
以上来自于百度翻译 以下为原文 How to test the UART in Explorer 16 board ? We are using PIC24F32KA304 as our PIM. We tried to write a know value in source code , but the thing is it is not appearing in the Console(Putty/Teraterm). And also we probed the TX pin using CRO and it is showing that value. Please help us to get it in Console as well. |
|
相关推荐
11个回答
|
|
|
|
|
|
这看起来像是一个重复的帖子,尽管OP有一个不同的用户名称。
以上来自于百度翻译 以下为原文 That really looks like a duplicate post though the OP has a different user name. http://www.microchip.com/forums/m948820.aspx |
|
|
|
实际上,我们按要求要求波特率达到9600。所以我认为它是正确的。
以上来自于百度翻译 以下为原文 Actually we tried with 9600 baud rate as per the requirement. so i think its correct only. |
|
|
|
显示配置设置和设置振荡器的最小代码,UART,并将字符写入UART。苏珊。
以上来自于百度翻译 以下为原文 Show us the config settings and the minimal code that sets up the oscillator, the UART and writes a character to the UART. Susan |
|
|
|
如果原始海报能做到这一点,他们会提出一个更好的问题。他们可能需要的是一个例子,可以为他们工作。这里有一个:我没有PIC23F32KA304 PIM模块为我的Explorer16,所以这个代码没有在真实的硬件中测试。它在模拟器中工作,所以给它一个机会。
以上来自于百度翻译 以下为原文 If the Original Poster could do this they would be asking a better question. What they may need is an example that could work for them. Here is one:/* * File: main.c * Target: PIC24F32KA304 * IDE: MPLABX v3.35 * Compiler: XC16 v1.26 * Target hardware: 44-pin PIM in the Explorer16 * * Description: * This is a mostly brain dead demo of using the UART on the * Explorer16 with the PIC24F32KA304 44-pin PIM. * * Notes: * * PIC24F32KA304 * +----------+ +----------+ +----------+ +----------+ * LCD_RS <> 1 : RB9 : LED_D4 <> 12 : RA10 : LED_D9 <> 23 : RB2 : Y1-32KHZ <> 34 : RA4/SOSCO: * LCD_D6 <> 2 : RC6 : LED_D5 <> 13 : RA11 : LED_D10/SW5 <> 24 : RB3 : LED_D3 <> 35 : RA9 : * LCD_D7 <> 3 : RC7 : SW6 <> 14 : RB14 : LCD_D0 <> 25 : RC0 : LCD_D3 <> 36 : RC3 : * LED_D6 <> 4 : RC8 : SCSn <> 15 : RB15/SS1n: LCD_D1 <> 26 : RC1 : LCD_D4 <> 37 : RC4 : * LED_D7 <> 5 : RC9 : GND -> 16 : AVSS : LCD_D2 <> 27 : RC2 : LCD_D5 <> 38 : RC5 : * SW3 <> 6 : RA7 : PWR -> 17 : AVDD : PWR -> 28 : VDD : GND -> 39 : VSS : * INT2 <> 7 : RA6/INT2 : MCLR -> 18 : RA5/MCLR : GND -> 29 : VSS : PWR -> 40 : VDD : * MSDI <> 8 : RB10/SDI1: POT <> 19 : RA0 : OSCI <> 30 : RA2/OSCI : PGD <> 41 : RB5/PGD3 : * SCK <> 9 : RB11/SCK1: TEMP <> 20 : RA1 : OSCO <> 31 : RA3/OSCO : PGC <> 42 : RB6/PGC3 : * LED_D8 <> 10 : RB12 : U2TX <> 21 : RB0/U2TX : SW4 <> 32 : RA8 : LCD_E <> 43 : RB7 : * MSDO <> 11 : RB13/SDO1: U2RX <> 22 : RB1/U2RX : Y1-32KHZ <> 33 : RB4/SOSCI: LCD_RW <> 44 : RB8 : * +----------+ +----------+ +----------+ +----------+ * TQFP-44 * */ /* * Configuration words */ #pragma config BWRP = OFF, BSS = OFF, GWRP = OFF, GSS0 = OFF, FNOSC = FRC #pragma config SOSCSRC = ANA, LPRCSEL = LP, IESO = OFF, POSCMOD = NONE #pragma config OSCIOFNC = OFF, POSCFREQ = HS, SOSCSEL = SOSCLP, FCKSM = CSECMD #pragma config WDTPS = PS32768, FWPSA = PR128, FWDTEN = SWON, WINDIS = OFF #pragma config BOREN = BOR0, LVRCFG = OFF, PWRTEN = OFF, I2C1SEL = PRI #pragma config BORV = V18, MCLRE = ON, ICS = PGx3, DSWDTPS = DSWDTPSF #pragma config DSWDTOSC = LPRC, DSBOREN = OFF, DSWDTEN = OFF /* * Target specific definitions */ #include /* * Standard library definitions */ #include /* * Application specific definitions */ #define FOSC (8000000UL) #define FCYC (FOSC/2UL) /* * Definition for UART setup */ #define UARTNUM 2 /* Which device UART to use */ #define BAUDRATE 9600L /* Baud rate */ #define USE_HI_SPEED_BRG /* Use BRGH=1, UART high speed mode */ /* UART Baud Rate Calculation */ #ifdef USE_HI_SPEED_BRG #define BRG_DIV 4L #else #define BRG_DIV 16L #endif #define BAUDRATEREG (((FCYC + (BRG_DIV * BAUDRATE / 2L)) / (BRG_DIV * BAUDRATE)) - 1L) #define BAUD_ACTUAL (FCYC/BRG_DIV/(BAUDRATEREG+1)) #define BAUD_ERROR ((BAUD_ACTUAL > BAUDRATE) ? BAUD_ACTUAL-BAUDRATE : BAUDRATE-BAUD_ACTUAL) #define BAUD_ERROR_PRECENT ((BAUD_ERROR*100L+BAUDRATE/2L)/BAUDRATE) #if (BAUD_ERROR_PRECENT > 3) #error "UART frequency error is worse than 3%" #elif (BAUD_ERROR_PRECENT > 2) #warning "UART frequency error is worse than 2%" #endif /* UART Configuration */ #define UARTREG2(a,b) U##a##b #define UARTREG(a,b) UARTREG2(a,b) #define UxMODE UARTREG(UARTNUM,MODE) #define UxBRG UARTREG(UARTNUM,BRG) #define UxSTA UARTREG(UARTNUM,STA) #define UxRXREG UARTREG(UARTNUM,RXREG) #define UxTXREG UARTREG(UARTNUM,TXREG) #define UxMODEbits UARTREG(UARTNUM,MODEbits) #define UxSTAbits UARTREG(UARTNUM,STAbits) #define UxTX_IO UARTREG(UARTNUM,TX_IO) const int __C30_UART = UARTNUM; /* * Initialize this PIC hardware */ void Init_PIC(void) { unsigned int ClockSwitchTimeout; /* * Disable all interrupt sources */ __builtin_disi(0x3FFF); /* disable interrupts for 16383 cycles */ IEC0 = 0; IEC1 = 0; IEC2 = 0; IEC3 = 0; IEC4 = 0; IEC5 = 0; __builtin_disi(0x0000); /* enable interrupts */ _NSTDIS = 1; /* disable interrupt nesting */ /* * Set system oscillator to 8MHz using the internal FRC. */ if(OSCCONbits.CLKLOCK == 0) /* if primary oscillator switching is unlocked */ { __builtin_write_OSCCONH(0x00); /* select FRC as primary clock source */ __builtin_write_OSCCONL(OSCCON | (1<<_OSCCON_OSWEN_POSITION)); /* wait for clock to switch */ for(ClockSwitchTimeout = 60000; ClockSwitchTimeout; ClockSwitchTimeout--) { if(!OSCCONbits.OSWEN) break; } /* primary oscillator is now 8MHz for a 4MIPS instruction cycle */ } /* * Make all pins digital GPIO */ ANSA = 0; ANSB = 0; ANSC = 0; } /* * SETUP UART: No parity, one stop bit, polled */ void Init_UART(void) { UxMODE = 0; /* reset UART */ UxSTA = 0; UxMODEbits.UARTEN = 1; /* enable UART */ UxBRG = BAUDRATEREG; /* set baud rate */ #ifdef USE_HI_SPEED_BRG UxMODEbits.BRGH = 1; /* use high speed mode */ #else UxMODEbits.BRGH = 0; /* use low speed mode */ #endif UxSTAbits.UTXEN; /* Enable TX */ } /* warning non-portable function */ /* * This function waits for the at least the * specified number milliseconds then returns. */ void delay(unsigned long wait_ms) { while(wait_ms) { asm(" repeat %0 n" " clrwdt n" : /* no outputs */ : "r" (FCYC/1000-1) ); wait_ms = wait_ms - 1; } } /* * Main application */ int main(void) { /* * Setup hardware */ Init_PIC(); Init_UART(); delay(20); /* * Show the world we are ready */ printf("Hello world.rn"); /* * Application process loop */ for(;;) { if(UxSTAbits.OERR) { /* Clear overrun error and reset receiver */ UxSTAbits.OERR = 0; } else { /* Echo character to UART */ if(UxSTAbits.URXDA) { putchar(UxRXREG); } } } return 0; } I do not have a PIC23F32KA304 PIM module for my Explorer16 so this code is not tested in real hardware. It does work in the simulator so give it a shot. |
|
|
|
@Dan-我同意配置设置,但我认为您的代码示例可能过于通用和复杂,无法实现OP。您还使用了“printf”函数,该函数需要定义一个“putchar”(或者类似的函数,这里按内存传递)来告诉它使用哪个UART。(这在模拟器上可能有所不同,这也是它为什么适合您的原因。)我当时的思路是:(从内存中写入,没有测试)我知道没有错误检查等等,但是应该发送稳定的“X”字符流,以确保到PC的连接是wo稍后,可以添加用于检查接收到的字符并与之相呼应的代码(或任何东西)来完成循环。苏珊
以上来自于百度翻译 以下为原文 @Dan - I agree with the config settings but I think your code example is possibly too generic and complex to get the OP under way. Also you use the 'printf' function that needs a 'putchar' (or similar function - going by memory here) defined to tell it which UART to use. (This may be different on the simulator which is why it is working for you.) I was thinking more along the lines of: #include // config pragmas go here int main(void) { // Set up the oscillator if you are not using the 8MHz FRC // Set the UART Tx an dRx pins to 'digital' ANSB = 0; // Actually set all of the PORTB pins to 'digital' TRISBbits.TRISB0 = 0; // Set the Tx pin to output, the Rx pin is input by default U2BRG = 25; // Set the baud rate ( see Example 18-1 in the data sheet) U2MODE = 0; // Should be all 0 anyway but just in case // Actually no further changes are needed as the default settings are good for a test U2STA = 0; // Again not really necessary but doesn't hurt U2MODEbits.UARTEN = 1; // Enable the UART U2STAbits.UTXEN = 1; // Enable the transmitter while(1) { while( 1 == U2STAbits.UXTBF); // Wait until the Tx buffer can take 1 more character U2TXREG = 'X'; } return 0; // Just needed to keep the compiler happy as we wil never get out of the main 'while' loop } (Written from memory and not tested) I know there is no error checking etc. but that should be sending a steady stream of "X" characters to make sure that the connection to the PC is working. Later on code for checking for received characters and echoing them (or whatever) can be added to complete the loop. Susan |
|
|
|
虽然我没有用于Explorer16的MA240022-PIC24F32KA304插件模块,但我确实有一个MA240019-PIC24FJ64GB004 PIM。关于“i n t_C30_UART”定义的r指南)有可能得到标准的C库函数p i n t f()和p u t c h a r()以使用XC16(免费)编译器。不需要对传统plib的支持,在Microchip标准库的某个地方是对映射到低级“write()”函数的p u t c h a r()的定义。这里是在真实硬件上测试的复制:https://github.com/dsoze1...24FJ64GB004_Explorer16
以上来自于百度翻译 以下为原文 While I do not have a MA240022 - PIC24F32KA304 Plug-in Module for my Explorer16 I do have a MA240019 - PIC24FJ64GB004 PIM. The PIC24FJ64GB004 has may things that are different from the PIC24F32KA304 it is close enough to debug my code in real hardware. Using some deeply buried hooks (see compiler user guide about the "int __C30_UART" definition) it is possible to get standard C library function p r i n t f () and p u t c h a r () to work with the XC16(free) compiler. Legacy plib support is not required and somewhere in the Microchip standard library is the a define for p u t c h a r () that maps to a low level "write()" function. My code does have ALL of the necessary fluff to build a complete application that does in fact run on real hardware. You can find my application that was tested on real hardware here: https://github.com/dsoze1...24FJ64GB004_Explorer16 |
|
|
|
肯定是在微软芯片似乎无法修复的愚蠢防火墙列表中。
以上来自于百度翻译 以下为原文 c h a r ( is certainly in the stupid firewall list that Microchip seem incapable of fixing. |
|
|
|
大家好,我正在尝试为使用MPLABX IDE v3.35并使用XC16作为编译器创建的十六进制文件创建校验和。为了计算校验和,我刚在项目属性中添加了以下内容“构建后执行此行”“C:/Program Files(x86)/Micro./MPLABX/v3.35/mplab_ide/mplab_ide/./.”。.../bin/hex.”dist/{CND_CONF{CND_CONF}/{CND_CND_CONF}/${IMAGE_TYPE}/项目名称{IMAGE_TYPE}/{IMAGE_TYPE}/项目名称。{IMAGE_TAGE_TYPE}.{IMAGE_TAGE_TYPE}..{{IMAAAAGE_TAGE_TYPE}............/bin/bin/bin/bin/bin/bin/bin/六六六六六/六六六六六六六六六六六六六六己己己队队队队队队队队队队队队队队队队队化编TPUT_SUFFIX}但是当我构建时,它就会失败,并显示如下“用户定义的post-bui”步骤:[“C:/程序文件(x86)/Micro芯片/MPLABX/V3.35/MPLABX/V3.35/MPLABX/MPLABX/MPLABX/V3.35/mplab_ide/mplab_ide/mplab_ide/mplab_ide/v3.3/3.35/本/六六六六六六六六六六”/六六六六六六六六六六:[[C C:/C:/C:/C:/C:/程序文件/程序文件/X86文件/X86/X86/X86/X86/X866/X86866/X86X/X86X/X8686X/微芯片/Micro芯片/微处理器/微芯片/微芯片/微芯片/微芯片/MPLABX/MPecipe for target'.build-conf'failedmake[1]:离开目录“E:/Project_Folder/Project_Name”nbproject/Makefile-impl.mk:39:.pe for target'.build-impl'failed(141)不能打开输入文件“dist/default/”:Permission deniedmake[1]:***[.build-conf]Error 1make: ***[.build-impl]Error 2BUILD F挂载(退出值2,总时间:8s),我还尝试运行该工具作为管理员。但是我和上面提到的一样,请帮助我解决这个问题。谢谢。
以上来自于百度翻译 以下为原文 Hi all, I am trying to create a checksum for the hexfile created using MPLAB X IDE v3.35 and using XC16 as compiler. For Calculating Checksum i just added the following in project properties "Execute this line after build " "C:/Program Files (x86)/Microchip/MPLABX/v3.35/mplab_ide/mplab_ide/modules/../../bin/hexmate" dist/${CND_CONF}/ ${IMAGE_TYPE}/Project_Name.${IMAGE_TYPE}.${OUTPUT_SUFFIX} -FILL=w1:0x00@0x1200:0x56FB -CK=1200-56FB@56FCw2g7 -odist/${CND_CONF}/${IMAGE_TYPE}/Project_Name.${IMAGE_TYPE}.${OUTPUT_SUFFIX} But when I do build it gets failed and shows the following "User defined post-build step: [ "C:/Program Files (x86)/Microchip/MPLABX/v3.35/mplab_ide/mplab_ide/modules/../../bin/hexmate" dist/default/ production/Project_Name.production.hex -FILL=w1:0x00@0x1200:0x56FB -CK=1200-56FB@56FCw2g7 -odist/default/production/Project_Name.production.hex]" nbproject/Makefile-default.mk:97: recipe for target '.build-conf' failed make[1]: Leaving directory 'E:/Project_Folder/Project_Name' nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed (141) can't open input file "dist/default/": Permission denied make[1]: *** [.build-conf] Error 1 make: *** [.build-impl] Error 2 BUILD FAILED (exit value 2, total time: 8s) And i also tried to run the tool as administrator. But getting the same as i mentioned above. Kindly please help me to resolve this. Thanks |
|
|
|
Antony,做你自己的事。你的题目和原来的有很大的不同。
以上来自于百度翻译 以下为原文 Antony, Make your own thread. Your subject is quite different from original one... Regards |
|
|
|
|
|
|
|
只有小组成员才能发言,加入小组>>
5160 浏览 9 评论
1998 浏览 8 评论
1927 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3170 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2225 浏览 5 评论
731浏览 1评论
613浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
503浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
629浏览 0评论
527浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-22 17:04 , Processed in 1.577955 second(s), Total 97, Slave 80 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号