完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
我是一个新的和声框架,我想把我的一个项目从一个普通的MPLAB环境转移到ValueV1.10框架。为此,我想首先实现一个测试UART通信,比如Hello World:当接收到“A”字符时,一个LED亮起。我想通过RX上的中断来实现这种通信。我阅读了很多教程和指南,对驱动程序的系统接口、驱动程序的客户端接口、动态驱动程序或静态驱动程序的概念有点困惑。但是,如果我理解正确,我必须使用一个静态驱动程序(“只使用驱动程序的一个实例”)和一个字节传输模型。因此,当我在StulyBuff.c中生成代码时,DrviUsARTHOTASKSSEVELVER()在DRVIUS UARTARXIMAN C中定义:并且DRVIUSAART00TASKSSEVELVER()定义在DRVIUS UARTARSHIDECT.C中:我认为这个最后一个任务,DRVIUSART00TASKSSEVER(),是我必须插入代码的地方。读取字节并检查它最终打开LED。这里是我的疑问:如果我在DRVIUSART00TASKSSEVELVER()中写下这一点,是正确的吗?因为在MPLAB®和声帮助-驱动库中,我读到(PG 6),一个客户端接口(例如,由DrviUsARTHARADEQUEL字节(AppDATA,MySART)函数进行RAPDIVE)被称为API和(PG 1013),API(除非另有规定)不应该从中断上下文调用。也就是说,它们不应该从ISR或在ISR上下文中执行的事件处理程序调用。“所以我的问题是:我的代码是正确的吗?如果不是,在ISR内部获得字节的正确方法是什么?
以上来自于百度翻译 以下为原文 I'm new to HARMony framework and I want to transfer one of my projects from a common MPLAB environment to the Harmony v1.10 framework. For this reason I want first implement a test UART communication like an Hello World: when receives the "A" character a LED turns on. And I want implement this communication via Interrupt on RX. I read many tutorials and guides and I'm a bit confused on the concepts of a Driver's System Interface, Driver's Client Interface, dynamic driver or static driver. However, if I understood correctly, I have to use a static driver ('cause use only one instance of driver) with the interrupt on and a Byte Transfer Model. So, when I generate the code I have in the system_interrupt.c void __ISR(_UART1_TX_VECTOR, ipl0AUTO) _IntHandlerDrvUsartTransmitInstance0(void) { DRV_USART_TasksTransmit(sysObj.drvUsart0); } void __ISR(_UART1_RX_VECTOR, ipl1AUTO) _IntHandlerDrvUsartReceiveInstance0(void) { DRV_USART_TasksReceive(sysObj.drvUsart0); } void __ISR(_UART1_FAULT_VECTOR, ipl0AUTO) _IntHandlerDrvUsartErrorInstance0(void) { DRV_USART_TasksError(sysObj.drvUsart0); } Now the DRV_USART_TasksReceive() is defined in the drv_usart_mapping.c: void DRV_USART_TasksReceive ( SYS_MODULE_OBJ object ) { switch(object) { case DRV_USART_INDEX_0: { DRV_USART0_TasksReceive(); break; } default: { break; } } } and the DRV_USART0_TasksReceive() is defined in the drv_usart_static.c: void DRV_USART0_TasksReceive(void) { /* This is the USART Driver Receive tasks routine. If the receive interrupt flag is set, the tasks routines are executed. */ /* Reading the receive interrupt flag */ if(SYS_INT_SourceStatusGet(INT_SOURCE_USART_1_RECEIVE)) { /* Clear up the interrupt flag */ SYS_INT_SourceStatusClear(INT_SOURCE_USART_1_RECEIVE); } } I think that this last task, DRV_USART0_TasksReceive(), is where I have to insert my code to read the byte and check it to turn on the LED eventually. And here come my doubt: is correct if I write the following in the DRV_USART0_TasksReceive()? void DRV_USART0_TasksReceive(void) { /* This is the USART Driver Receive tasks routine. If the receive interrupt flag is set, the tasks routines are executed. */ /* Reading the receive interrupt flag */ if(SYS_INT_SourceStatusGet(INT_SOURCE_USART_1_RECEIVE)) { if(!DRV_USART_ReceiverBufferIsEmpty()) { __uint8_t byte = DRV_USART_ReadByte(appData.myusart); if(byte=='A') { LED_ON(); } } /* Clear up the interrupt flag */ SYS_INT_SourceStatusClear(INT_SOURCE_USART_1_RECEIVE); } } Because in the MPLAB® Harmony Help - Driver Libraries I read (pg. 6) that a Client Interface (rappresented by the DRV_USART_ReadByte(appData.myusart) function, for example) is called an API and (pg. 1013) that an API "unless otherwise specified, should not be called from an interrupt So my question is: Is my code correct? If not, what is the correct metod to obtain a byte inside the ISR? |
|
相关推荐
12个回答
|
|
|
嗨,最重要的是确保你在MHC中正确配置了USAT。你能在MHC中显示USAT设置的截图吗?RegardsBTW:我相信在www. McChIPDealEng.com网站上有一些实验室展示了如何在协调训练材料中使用USAT。
以上来自于百度翻译 以下为原文 Hi, the most important is to be sure that you have correctly configured USART in MHC. Can you show a screenshot of the USART setup in MHC ? Regards BTW : I believe there are some labs in the www.microchipdeveloper.com website showing how to use the USART in the Harmony training material |
|
|
|
|
|
抱歉,但是当我尝试附加图像时,编辑器告诉MeAccess你没有权限访问“http://www. McCys.com /论坛/上载.ASPX”在这个服务器上。参考文献18.C40F2DC1.148356953.845 F8E5I不明白为什么。
以上来自于百度翻译 以下为原文 Sorry, but when I try to attach an images, the editor tell me Access Denied I don't understand why. |
|
|
|
|
|
但是,这是连接到图像的HTTP//I.IMGURUR.COM/F0B0RVV.JPG。
以上来自于百度翻译 以下为原文 However, this is the link to image http://i.imgur.com/f0b0RvV.jpg |
|
|
|
|
|
|
|
|
|
|
|
我有同样的问题,我试着发送数据。你让它工作了吗?
以上来自于百度翻译 以下为原文 I've the same question , I try to send data . Do you make it working ? |
|
|
|
|
|
相反,我不知道这是否会产生影响。另外,我使用静态驱动程序,并且UsARToMultEdieSoID和StistNoID的模型非常令人困惑。
以上来自于百度翻译 以下为原文 Instead of __uint8_t byte = DRV_USART_ReadByte(appData.myusart); I use if (!PLIB_USART_ReceiverDataIsAvailable(usartId)) break; appUSARTbufferTable[usartId].rxRing.pBuffer[(writeIndex + i) % ringSize] = PLIB_USART_ReceiverByteReceive(usartId); Don't know whether that makes the difference. Also, I do use the static driver. And the model of USART_MODULE_ID and instanceId is quite confusing. HTH Nick |
|
|
|
|
|
还没有!但下周我会尝试MuleleN尼克解决方案。谢谢MueleN尼克给你的建议。那么我的代码在DrviUsART00TASKSSEVER()应该是什么?????
以上来自于百度翻译 以下为原文 Not yet! But the next week I'll try the muellernick solution. Thanks muellernick for your suggestion. Then my code in the DRV_USART0_TasksReceive() should be void DRV_USART0_TasksReceive(void) { /* This is the USART Driver Receive tasks routine. If the receive interrupt flag is set, the tasks routines are executed. */ /* Reading the receive interrupt flag */ if(SYS_INT_SourceStatusGet(INT_SOURCE_USART_1_RECEIVE)) { if (!PLIB_USART_ReceiverDataIsAvailable(usartId)) break; int8_t byte = PLIB_USART_ReceiverByteReceive(usartId); if(byte=='A') { LED_ON(); } /* Clear up the interrupt flag */ SYS_INT_SourceStatusClear(INT_SOURCE_USART_1_RECEIVE); } } ???? |
|
|
|
|
|
我发现了这个例子: Microchip Hyror V2Y02Y0BBApp\驱动程序UARTAR.UARTARECHORE,它们使用静态模式下的中断。为什么使用一个中断来协调是如此复杂,我使用MCHP已经很多年了,我尝试和谐,这是一个耻辱。我所看到的所有文档和视频都在相同的样本,没有什么有趣的
以上来自于百度翻译 以下为原文 I've found this example C:microchipharmonyv2_02_00bappsdriverusartusart_echo they use the interrupt in static mode. Why it is so complicated to use an interrupt in Harmony , I've been using MCHP for many years and I try Harmony and it is a shame. All the documentation and video I saw are on the same sample and nothing interesting |
|
|
|
|
|
我站在你这边!我首次使用和声,只为蓝牙堆栈专有库。这是一个完美的开始,知道它是好的还是坏的框架。
以上来自于百度翻译 以下为原文 I'm on your side! I'm using Harmony for the first time only for the Bluetooth Stack proprietary libraries. This is the perfect moment to start with it and know if it's a good or bad framework. |
|
|
|
|
|
嗨,Thoraz和FFB,我建议大家先对和声驱动程序有一个基本的了解,然后再试试。“第四卷:MPLAB和谐框架参考和GT;驱动程序库帮助&驱动程序库概述”和声部分帮助AtWorksUnc:Microchip HealthV2Y02YY0Bdoc。深入潜水,但只需要一个概述,你总是可以回来了解更多,当你尝试使用它。来到你的方法,你不应该修改任何驱动程序代码!驱动程序为您提供了可以用来完成任务的API。对于一个实例,您不应该修改DrviUsART00tasksAccess实现。该API将给出回调(您在向驱动程序添加请求时注册),或者它的工作并出来并对应用程序进行控制。有三种型号的USAT驱动程序与你可以在不同的用途中使用的1种方式相协调。字节模型2。读写或文件I/O模型3。缓冲队列模型,您可以通过读取UnART驱动程序和声帮助来理解这些,“第四卷:MPLAB和谐框架参考和GT;驱动程序库帮助& USAT驱动程序库”。如果您想尝试字节模型的简单示例,那么尝试“C:Microchip HyrameV2Y02Y0B\AppsExcel”示例。如果您想尝试缓冲队列模型,那么在“C:Microchip Hyror V2Y02YY0BAppDealsUSAT”上进行2个演示:“我会告诉您不要修改任何演示代码,只需尝试演示,并尝试理解流程。然后您可以轻松启动应用程序开发。-)
以上来自于百度翻译 以下为原文 Hi Thoraz and ffb, I suggest you guys to get a basic understanding of the the Harmony drivers first and then try them. "Volume IV: MPLAB Harmony Framework Reference > Driver Libraries Help > Driver Library Overview" section of Harmony help at document under C:microchipharmonyv2_02_00bdoc. Don't dive deep, but just take a overview and you can always come back to understand more as and when you try using it. Coming to the approach of you, You should not be modifying any driver code! Driver gives you APIs those you can use to get your job done. For an instance, you should not modify DRV_USART0_TasksReceive implementation. This API will either give a callback( that you registered while adding request to the driver) or does it's job and come out and gives control to the application. There are three models of USART driver in Harmony those you can use in different purposes, 1. Byte model 2. Read Write or File I/O model 3. Buffer queue model You can understand about these by reading USART driver section of harmony help, "Volume IV: MPLAB Harmony Framework Reference > Driver Libraries Help > USART Driver Library" If you want to try simple example of byte model, then try "C:microchipharmonyv2_02_00bappsexamplesperipheralusart" If you want to try Buffer queue model, then go for 2 demos at "C:microchipharmonyv2_02_00bappsdriverusart" I'll tell you don't modify any demo code, just try the demos as is and try to understand the flow. Then you can easily start your application development. Happy learning. :-) |
|
|
|
|
|
哦,等等,这里是我的ISR(其中一个):如果AppUsUARTHARDWADSBooReWrad(我的代码)返回true,那么我的发送缓冲区IST被处理,中断必须被关闭(或者你将永远获得一个发送缓冲区空INT)。
以上来自于百度翻译 以下为原文 Oh wait, here is my ISR (one of them): void __ISR(_UART_1_VECTOR, ipl1AUTO) IntHandlerDrvUsartInstance0(void) { if (SYS_INT_SourceStatusGet(INT_SOURCE_USART_1_RECEIVE)) { APP_USARTHardwareBufferRead(USART_ID_1); PLIB_INT_SourceFlagClear(INT_ID_0, INT_SOURCE_USART_1_RECEIVE); } if (SYS_INT_SourceStatusGet(INT_SOURCE_USART_1_TRANSMIT)) { bool intDisable = APP_USARTHardwareBufferWrite(USART_ID_1, INT_SOURCE_USART_1_TRANSMIT); PLIB_INT_SourceFlagClear(INT_ID_0, INT_SOURCE_USART_1_TRANSMIT); if (intDisable) PLIB_INT_SourceDisable(INT_ID_0, INT_SOURCE_USART_1_TRANSMIT); } // Clear possibly remaining pending interrupt and clear the receive buffer if (SYS_INT_SourceStatusGet(INT_SOURCE_USART_1_ERROR)) { APP_USARTHardwareBufferClearErr(USART_ID_1); PLIB_INT_SourceFlagClear(INT_ID_0, INT_SOURCE_USART_1_ERROR); } } If APP_USARTHardwareBufferWrite (my code) returns true, then my send buffer ist processed and the interrupt has to be switched off (or you will get a transmit buffer empty INT for ever). Nick |
|
|
|
|
|
OrthyV202B-使用UART RX WorksCurror(禁用Tx和错误中断,错误中断在启用时导致随机数据故障)------------------MHCV2024UART,静态、中断、字节模型+回调(非阻塞)----------------- Txbool bUartTx(UARTES EU,UIT88T UDATA)//非阻塞(如果不发送则返回false){if(!)!DrviUsARTHEngPuffeSeriSULL(SUART[EU]句柄)/ /如果UART TX FIFO具有空间{DRVU.UARTARGWORKETENEL字节(SUART [EU]句柄,UDATA);//输出数据SUARTAR[EU]。UTXCOUNT++;返回(true);}返回(false);/ /没有空间用于Tx} VUARTTX(EUARTES EU,UIT88UT UDATA)/ /阻塞{(DrvuasAtARTU-TURMI)tBuffelISFULL(SUART[EU]句柄){{/*Walth*/} / /如果UART TX具有空间DrvU.AtARTHARDIGETELL字节(SuART[Eu]句柄,UDATA);//输出数据}---------------init多个UART与CalbutSuin88t PUUARTITIDENET[EULISTRONT] = {DRVU.UARTARXIDEXX0 0,DRVIUASARTI索引X1,DRVIUS UARTARXIDEX2,DRVIUS USAARTI索引3在Initprintf(“OpenUART:”)中允许重新映射EUART实例;(EU=0;Eu& lt;EulistEnter;Eu+++)/检查RX数据{UARTEX= EUE]的所有UART。UTS(“n”);PrtTf(“%s”,PPCuARTeNe[Eu]);Suale[Eu]。句柄= DRVIUSAARTHOPENT(SUART[EU] UDCHIVE,DRVYIOIN ItNeTyRead Read DrvyIOIONTIN非阻塞);/todo:ItrimyV202b中的意图不做任何事(DrvH-AdLeIOAL==SuART[Eu]句柄)/*打开错误?检查句柄是否有效*/{PrtTf(“**uARTITITVIRT[%s] ***n”,PPCuARTeNe[Eu]);} DRVIUTARETECVECVECARECABSET(SUART [Eu]VCARBACKIOSUARTARJORX(const SysMuleMeX索引UDATA){UTI8EYTURUDATA;UTI88UTURX字节=0;//用于更新SUART [UnCurry]。URXMAX交换机(UQUEST)/ / UART { EuDiag:外壳EUXP:CASE EULA:情况EULB:EUOO:CASE EUOB://我的Uarts IF(DRVIUS UsARTHARVER VBR)(SUART [UnQual]句柄){SUART [UnQue],BRXNONE= TRUE;} //获得PIC32 MZ的数据{//DrvuSuthARTAccess VBuffSersieGETE()==8字节,同时(!)DrviUsRealFuffelFielSISULL(SUART [UnQue]句柄)//读取UART FIFO直到空{ //OLIDHHOTGGELE();;/SUART [UnQue][x]句柄);SuART[uQue] UrxCuth++;BruBuff88Adl(PPUARTrxRunBufs[uClult],UDATA);和/或您的缓冲选择,如果URX字节[gt;SuART[uQue] UrxMax){SuART[UnQuest.UrxMax=URXBythOb];//RX FIFO深度峰值检测器,可以帮助检测如果系统对数据速率太慢,则中断;默认值:UUARTARTEXIDENDIDCOUNTION+++;BREACK;} ------------MunPUTC,用于将PrimTF映射到所需的UART(替换系统默认值)ValueMun-Putc(char cByb)/重定向STDIO到EUDIAG{{//REF:http://MychIpPrdult/COX/XC32:重定向:-如果您的代码{VuARTTXBEL(EUDIAG,CBOLL)中启用了缓冲(StdOUT)/可选的检查,则/ /通过缓冲区输出/否则/直接输出到端口(在系统异常期间有用,调试Uart Buffering等){(DrvuSuthARTApple BuffeSeriSULL(DY-DGJI IN)){/*Walth**/}//等待直到空间(阻塞)DrviUsARTHARCHEADEYBEY(DY-DGYIN TythHANDLE,cBEYE);//直接输出数据到EUDIAG}} ------------ISR(未修改的生成系统Sypult.c)ValuyO.ISR(uUART1xTXY向量,IPL0AUTO)。[0UTAR1ORXY向量,IPL1AUTO),in thundLrdvARSARTIFESTATION 0(空隙){DrvU.AtARTHEASTASKS接收(SysObj.DrVuSART0);} Vo.Y-ISR(保罗,UART1IOFARTTHORE向量,IPL0AUTO)。TT
以上来自于百度翻译 以下为原文 HarmonyV202b - Using the callbacks for UART Rx works (Disable Tx and Error interrupts, the Error Interrupt causes random data glitches when enabled). --------------------- MHCv2024 UART, Static, Interrupt, Byte Model+Callback (non-blocking) --------------------- Tx bool bUartTx(EUARTs eU, uint8_t uData) //non-blocking (returns false if not sent) { if(!DRV_USART_TransmitBufferIsFull(sUart[eU].handle)) //If UART Tx FIFO has Space { DRV_USART_WriteByte(sUart[eU].handle, uData); // Output Data sUart[eU].uTxCount++; return(true); } return(false); //no space for Tx } void vUartTx(EUARTs eU, uint8_t uData) //blocking { while(DRV_USART_TransmitBufferIsFull(sUart[eU].handle)) {/*wait*/ } //If UART Tx has Space DRV_USART_WriteByte(sUart[eU].handle, uData); // Output Data } --------------------- Init multiple UARTs with Callbacks uint8_t puUartInitIndex[EuListend] = { DRV_USART_INDEX_0, DRV_USART_INDEX_1, DRV_USART_INDEX_2, DRV_USART_INDEX_3, DRV_USART_INDEX_4, DRV_USART_INDEX_5 }; //Allows re-Mapping EUART Instances during Init printf("OpenUart:"); for(eU=0; eU sUart[eU].uIndex = puUartInitIndex[eU]; //vUartDG_Init_puts("OpenUart:");vUartDG_Init_puts(ppcUartNames[eU]);vUartDG_Init_puts("n"); printf(" %s", ppcUartNames[eU]); sUart[eU].handle = DRV_USART_Open(sUart[eU].uIndex, DRV_IO_INTENT_READWRITE|DRV_IO_INTENT_NONBLOCKING);//ToDo: Intents do nothing in HarmonyV202b if(DRV_HANDLE_INVALID == sUart[eU].handle)/* Open Error? Check if the handle is valid */ { printf("*** UartInitFail[%s] ***n", ppcUartNames[eU]); } DRV_USART_ByteReceiveCallbackSet(sUart[eU].uIndex, vCallback_usart_rx); //unused: DRV_USART_ByteErrorCallbackSet(sUart[eU].uIndex, vCallback_usart_err); } printf("n"); --------------------- Callback void vCallback_usart_rx(const SYS_MODULE_INDEX uIndex) { uint8_t uData; uint8_t uRxBytes=0; // for updating sUart[uIndex].uRxMax switch(uIndex) //which UART { case EuDiag: case EuExp: case EuLA: case EuLB: case EuOA: case EuOB: //My Uarts if(DRV_USART_ReceiverBufferIsEmpty(sUart[uIndex].handle)) { sUart[uIndex].bRxNone = true; } else //Got Data { //DRV_USART_ReceiverBufferSizeGet()==8bytes for PIC32MZ while(!DRV_USART_ReceiverBufferIsEmpty(sUart[uIndex].handle))// Read Uart FIFO till empty { //oLEDH_Toggle(); //sUart[uIndex].bRx = true; //sUart[uIndex].uRxByte = DRV_USART_ReadByte(sUart[uIndex].handle); uRxBytes++; uData = DRV_USART_ReadByte(sUart[uIndex].handle); sUart[uIndex].uRxCount++; bRingBufA8_add(ppUartRxRingBufs[uIndex], uData);//Your choice of buffering, I have my own ring buffers } if(uRxBytes > sUart[uIndex].uRxMax){sUart[uIndex].uRxMax = uRxBytes;}//Peak Detector for Rx FIFO Depth used, Can help detect if system too slow for data rate } break; default: uUartIndexInvalidCount++; break; } } --------------------- mon_putc for mapping printf to desired UART (replaces system default) void _mon_putc(char cByte)//Redirect Stdio to EuDiag { // Ref: http://microchipdeveloper.com/xc32:redirect-stdout if(bUartInitOK)//Optional check if buffering enabled in your code { vUartTxByte(EuDiag, cByte);//Output via Buffer } else //Direct Output to port (Useful during system exceptions, debugging of Uart Buffering, etc.) { while(DRV_USART_TransmitBufferIsFull(D_DG_InitHandle)){/*wait*/} //Wait Till Space (Blocking) DRV_USART_WriteByte(D_DG_InitHandle, cByte); //Direct Output Data to EuDiag } } --------------------- ISR (Unmodified generated system_interrupt.c) void __ISR(_UART1_TX_VECTOR, ipl0AUTO) _IntHandlerDrvUsartTransmitInstance0(void) { DRV_USART_TasksTransmit(sysObj.drvUsart0); } void __ISR(_UART1_RX_VECTOR, ipl1AUTO) _IntHandlerDrvUsartReceiveInstance0(void) { DRV_USART_TasksReceive(sysObj.drvUsart0); } void __ISR(_UART1_FAULT_VECTOR, ipl0AUTO) _IntHandlerDrvUsartErrorInstance0(void) { DRV_USART_TasksError(sysObj.drvUsart0); } --------------------- Paul |
|
|
|
|
只有小组成员才能发言,加入小组>>
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
473 浏览 0 评论
5793 浏览 9 评论
2334 浏览 8 评论
2224 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3530 浏览 3 评论
1121浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
1095浏览 1评论
我是Microchip 的代理商,有PIC16F1829T-I/SS 技术问题可以咨询我,微信:A-chip-Ti
872浏览 1评论
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
473浏览 0评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-1 18:55 , Processed in 1.247688 second(s), Total 96, Slave 79 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
1152