完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我使用的是来自Microchip和谐教程的USAR STAtiC-WF32示例,但是我无法查看寄存器或变量中的发送/接收字节。我使用写字节函数发送一个字节“0B000 000 0101”,但是我不能使用RADEYBULL函数读取它。
以上来自于百度翻译 以下为原文 I am using usart-static-wf32 example from microchip hARMony tutorials but I am unable to view the sent/received byte in register or variable. I am transmitting a byte "0b00000101" using writebyte function but I cannot read it using readbyte function. void APP_Tasks ( void ) { switch ( appData.state ) { case APP_STATE_INIT: { bool appInitialized = true; if (appInitialized) { appData.state = APP_STATE_UTX4; // change state to USART TX } break; } case APP_STATE_URX4: // USART receive state { if (!DRV_USART0_ReceiverBufferIsEmpty()) { appData.rx4_byte = DRV_USART0_ReadByte(); // read received byte appData.tx4_byte = appData.rx4_byte + 1; // modifying received byte confirms it was received appData.state = APP_STATE_UTX4; // change state to TX } break; } case APP_STATE_UTX4: // USART transmit state { appData.tx4_byte = 0b00001010; // make sure the transmit buffer is not full before trying to write byte if(!(DRV_USART_TRANSFER_STATUS_TRANSMIT_FULL & DRV_USART0_TransferStatus()) ) { DRV_USART0_WriteByte(appData.tx4_byte); // send modified byte appData.state = APP_STATE_URX4; // change state to RX and wait for next received byte } } /* The default state should never be executed. */ default: { /* TODO: Handle error in application's state machine. */ break; } } } |
|
相关推荐
2个回答
|
|
你必须在模拟器中注入接收值。检查模拟器帮助-刺激-注册表注入-消息触发器
以上来自于百度翻译 以下为原文 You have to inject receive values into the simulator. Check out simulator help - stimulus - register injection - message trigger |
|
|
|
嗨,乔治,谢谢你给我的建议,现在我可以用注册表注入我收到的数据。我有一个关于SPI的问题,一旦我收到了USAT字节,我想初始化SPI并用SPI发送数据,打开连接到我的另一个模块的LED。IC32。请看一下下面的代码,并建议这是正确的方法。也可以使用寄存器注入来模拟SPI吗?另一件事,如果我使用上面的代码SPI,我的程序总是困在下面的while循环在系统初始化。你能告诉我问题是什么吗?
以上来自于百度翻译 以下为原文 Hi George, Thank you for the suggestion I looked into it and now I am able to receive the data I sent using register injection. I have another question regarding SPI once I have received the usart byte I want to initialize SPI and send data using SPI to turn on led of another module connected to my Pic32. Can you please have a look at my code below and suggest if this is the proper way to go about it. And also can I simulate SPI also using Register injection? case APP_STATE_URX4: // USART receive state { if (!DRV_USART0_ReceiverBufferIsEmpty()) { appData.rx4_byte = DRV_USART0_ReadByte(); // read received byte if (appData.rx4_byte == 0b00001010) { appData.state = APP_STATE_SPI_INIT; // change state to SPI } } break; } case APP_STATE_SPI_INIT: { if (DRV_SPI_STATUS(sysObj.spiObjectIdx0) == SYS_STATUS_READY) //Open SPI { appData.SPI_Handle = DRV_SPI_Open(DRV_SPI_INDEX_1, DRV_IO_INTENT_READWRITE); } if (appData.SPI_Handle != DRV_HANDLE_INVALID) { appData.state = APP_STATE_SPI_WRITE_LEC_IC; } break; } case APP_STATE_SPI_WRITE_LED_IC: { SPI_CSOn(); // Assert SPI Chip Select SPI_Write_Buffer_Handle = DRV_SPI_BufferAddWrite2(); appData.state = APP_STATE_LED; break; } Another thing if i use the above code for SPI my program is always stuck in the below while loop at system initialization. Can you please tell me what the problem might be? PLIB_TEMPLATE void SPI_BufferClear_Default( SPI_MODULE_ID index ) { spi_registers_t volatile * spi = ((spi_registers_t *)(index)); uint32_t dummy = 0u; /* For enhanced buffer mode, Read the SPIxBUF till RX FIFO gets empty */ if(1u == spi->SPIxCON.ENHBUF) { while(0u == spi->SPIxSTAT.SPIRBE) { /* Read the SPIxBUF to flush it */ dummy = spi->SPIxBUF; } |
|
|
|
只有小组成员才能发言,加入小组>>
5178 浏览 9 评论
2003 浏览 8 评论
1931 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3177 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2228 浏览 5 评论
738浏览 1评论
622浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
509浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
636浏览 0评论
533浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-27 02:39 , Processed in 1.345045 second(s), Total 80, Slave 64 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号