完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
我刚刚更新了我的XIDE并安装了XC 16编译器。我取消了dspic33ev256gm106。我写TX ISR例程有困难。由于某些原因,TX ISR没有经过成功的迭代。我在使用皮克特3。跟踪原应用程序TX调用后的TX ISR触发。然而,ISR从来没有中断过。我在ISR中休息,只看到它被击中一次。我不确定,如果我遗漏了什么。请帮助:
以上来自于百度翻译 以下为原文 I have just updated my XIDE and installed the XC 16 compiler. I am unsing dspic33ev256gm106. I am having trouble writing a TX ISR routine. For some reason, the TX ISR does not go through successful iterations. I am using Pickit3. I trace TX ISR firing after the original application tx call. However, ISR never breaks ever again. I put a break in the ISR and only see it being hit once. I am not sure, if I am missing something. Please help:) void uart2_init(void) { //rx_buffer[RX_BUFFER_SIZE]; rx_buffer_size = 0; rx_buffer_max_size = RX_BUFFER_SIZE; rx_buffer_head = 0; rx_buffer_tail = 0; //tx_buffer[TX_BUFFER_SIZE]; tx_buffer_size = 0; tx_buffer_max_size = TX_BUFFER_SIZE; tx_buffer_head = 0; tx_buffer_tail = 0; /* digital input & output */ _TRISC12 = 1; // Input _TRISB7 = 0; // output // map UART2 TX pin to port RB7, which is remappable RP39 _RP39R = 0x03; /* map UART2 RX pin to port RC12, which is remappable RP160 */ RPINR19bits.U2RXR = 0x3C; // set up the UART for default baud, 1 start, 1 stop, no parity U2MODEbits.LPBACK = 0; // disable LOOPBACK U2MODEbits.UEN = 0; U2MODEbits.ABAUD = 0; // Auto-Baud disabled U2MODEbits.STSEL = 0; // 1-stop bit U2MODEbits.PDSEL0 = 0; // No Parity, 8-Data bits U2MODEbits.PDSEL1 = 0; U2MODEbits.BRGH = 0; // Standard-Speed mode // 4 clock cycles per bit, 0 - 16 cycles per bit U2STAbits.URXISEL0 = 0; U2STAbits.URXISEL1 = 0; // Interrupt after TX buffer done U2STAbits.UTXISEL0 = 0; U2STAbits.UTXISEL1 = 1; // Interrupt after TX buffer done U2BRG = 11;// BRGH - 0, Baud Rate setting for 115200 (default) // 44 if BRGH is 1 IEC1bits.U2TXIE = 1; // Enable UART TX interrupt IEC1bits.U2RXIE = 1; // Enable UART RX interrupt U2MODEbits.UARTEN = 1; // Enable UART (this bit must be set *BEFORE* UTXEN) //U2STAbits.UTXEN = 1; // Enable the hardware control of the pin and link it to UART2 } int uart2_send_packet(unsigned char *message, int length) { int i = 0; if( ((tx_buffer_tail+1)%tx_buffer_max_size)==tx_buffer_head ) { // buffer is full return 0; } else { // load up as many bytes as possible while ( (((tx_buffer_tail+1)%tx_buffer_max_size)!=tx_buffer_head ) && i tx_buffer[tx_buffer_tail] = message; i++; tx_buffer_tail = (tx_buffer_tail+1)%tx_buffer_max_size; tx_buffer_size++; } U2STAbits.UTXEN = 1; return i; } } void __attribute__((interrupt, no_auto_psv)) _U2TXInterrupt(void) { IFS1bits.U2TXIF = 0; // Clear TX2 Interrupt flag if( tx_buffer_head!=tx_buffer_tail) { // there are things left to send while (U2STAbits.TRMT==0); U2TXREG = tx_buffer[tx_buffer_head]; tx_buffer_head = (tx_buffer_head+1)%tx_buffer_max_size; tx_buffer_size--; } else { U2STAbits.UTXEN = 0; } } |
|
相关推荐
5个回答
|
|
一旦启用,不要禁用UTXEN,只做一次-在您的UART安装代码,但不在ISR中。
以上来自于百度翻译 以下为原文 Once enabled, do not disable UTXEN and do it just once - in your UART setup code but not within the ISR. |
|
|
|
MBedder:我如何启动应用程序代码中的TX中断?我最初认为UTXEN将允许我在将字节写入缓冲区之后关闭ISR。我应该在U2TXRG中写入一个字节吗?
以上来自于百度翻译 以下为原文 MBedder:) How do I fire off TX Interrupts in the application code? I originally thought that UTXEN would allow me to fire off an ISR after writing bytes to the buffer. Should I write one byte into the U2TXREG instead? int uart2_send_packet(unsigned char *message, int length) { int i = 0; if( ((tx_buffer_tail+1)%tx_buffer_max_size)==tx_buffer_head ) { // buffer is full return 0; } else { // load up as many bytes as possible while ( (((tx_buffer_tail+1)%tx_buffer_max_size)!=tx_buffer_head ) && i tx_buffer[tx_buffer_tail] = message; i++; tx_buffer_tail = (tx_buffer_tail+1)%tx_buffer_max_size; tx_buffer_size++; } U2STAbits.UTXEN = 1; return i; } } |
|
|
|
如果不使用U2STAbits.UTXEN=1,我不能发出TX ISR调用;这似乎是唯一能够设置IFS1位的触发器。我尝试编写U2TXRG= TXYBuffer-[TXXBuffeRixHead ]来触发中断事件。
以上来自于百度翻译 以下为原文 I cannot raise a TX ISR call without using U2STAbits.UTXEN = 1; This seems to be the only trigger capable of setting IFS1bits.U2TXIF It is almost as if the UART TX isr is not operating at all. I have tried writing U2TXREG=tx_buffer[tx_buffer_head] to trigger an interrupt event. |
|
|
|
谢谢你,苏珊,我已经让代码工作了。我会发布ISR程序。我从Microchip参考开始,从他们的TX示例中直接从PDF中出来。由于某些原因,在第一次U2STAbits.UTXEN=1之后,我无法让TX ISR重复;我已经尝试了很多组合,但仍然无法实现缓冲区的TX ISR顺序重新加载。我已经解决了这个问题。一个DSPIC33 EV的工作例子对我来说很有帮助。我会清理我的代码并发布我的解决方案。
以上来自于百度翻译 以下为原文 Thank you Susan, I have made the code work. I will post the ISR routine. I started with the Microchip reference and literally followed their TX example right out of the PDF. For some reason, I could not get TX ISR to repeat after the first U2STAbits.UTXEN = 1; I have tried many combinations and still could not achieve the TX ISR sequential reloading of the buffer. I have been able to solve the issue. A working example for dspic33ev would go a long way for me. I will clean up my code and will post my solution. |
|
|
|
在DSPIC33 EV设备中的UART外围设备几乎与其他PIC24和DSIC33设备中的UART相同。如果有任何特殊的差异,他们会在数据表和适当的FRM部分中被调用。我想说的是,对于dsPIC33设备的任何PIC24,任何示例都会有很大帮助。苏珊
以上来自于百度翻译 以下为原文 The UART peripheral in the dsPIC33EV family of devices is almost identical to the UARTs in the other PIC24 and dsPIC33 devices. If there are any specific differences they would be called out in the data sheet and the appropriate FRM section. I would say that any example for any PIC24 of dsPIC33 device would go a long way to help you. Susan |
|
|
|
只有小组成员才能发言,加入小组>>
5170 浏览 9 评论
2001 浏览 8 评论
1931 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3176 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2228 浏览 5 评论
737浏览 1评论
620浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
509浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
635浏览 0评论
531浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-25 16:15 , Processed in 1.183386 second(s), Total 57, Slave 50 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号