• AVR Freaks

PIC32MX775f256h usart problem with HV2.06

Author
codeKnight
New Member
  • Total Posts : 15
  • Reward points : 0
  • Joined: 2019/06/03 02:03:56
  • Location: 0
  • Status: offline
2019/08/21 18:19:28 (permalink)
0

PIC32MX775f256h usart problem with HV2.06

Hi,everyone
I am using pic32mx775f256h  with H2.06. i got a problem when i use usart1 with interrupt mode. When i connect the usart1 to PC it work well,but if i connect the usart1's rx and tx pin together,that is selftest, the trasmit interrupt can generated five times and recv interrupt can generated three times,then no interrrup was generated again. i don't know why,below is my interrupt test code: 
 
 
void __ISR(_UART_1_VECTOR, ipl1AUTO) _IntHandlerDrvUsartInstance1(void)
{
uint8_t source = 0;
USART_ERROR err;
uint8_t status = 0,usart_value = 0;

//分辨中断源,取消使能,防止重复进入中断
if(SYS_INT_SourceStatusGet(INT_SOURCE_USART_1_TRANSMIT))
{
//status = SYS_INT_SourceDisable(INT_SOURCE_USART_1_TRANSMIT);
SYS_INT_SourceDisable(INT_SOURCE_USART_1_TRANSMIT);
SYS_INT_SourceStatusClear(INT_SOURCE_USART_1_TRANSMIT);
source = INT_SOURCE_USART_1_TRANSMIT;
SYS_MESSAGE("tramist\r\n");

}
if(SYS_INT_SourceStatusGet(INT_SOURCE_USART_1_ERROR))
{
//SYS_INT_SourceDisable(INT_SOURCE_USART_1_ERROR);
SYS_INT_SourceStatusClear(INT_SOURCE_USART_1_ERROR);
source = INT_SOURCE_USART_1_ERROR;
SYS_MESSAGE("error\r\n");
}
if(SYS_INT_SourceStatusGet(INT_SOURCE_USART_1_RECEIVE))
{
//SYS_INT_SourceDisable(INT_SOURCE_USART_1_RECEIVE);
SYS_INT_SourceStatusClear(INT_SOURCE_USART_1_RECEIVE);
source = INT_SOURCE_USART_1_RECEIVE;
SYS_MESSAGE("recv\r\n");
}

//DRV_USART_TasksTransmit(sysObj.drvUsart1);
//DRV_USART_TasksError(sysObj.drvUsart1);
//DRV_USART_TasksReceive(sysObj.drvUsart1);

switch(source)
{
case INT_SOURCE_USART_1_TRANSMIT:
if(g_ceshi < 5)
{
SYS_PRINT("#%d\r\n",g_buf[g_ceshi]);
PLIB_USART_TransmitterByteSend(USART_ID_1, g_buf[g_ceshi]);
g_ceshi++;
//PLIB_USART_TransmitterDisable(USART_ID_1);//wuhao
}
else
{
//PLIB_USART_TransmitterDisable(USART_ID_1);
//status = SYS_INT_SourceDisable(INT_SOURCE_USART_1_TRANSMIT);
//SYS_PRINT("$$$%d$$$\r\n",status);
g_ceshi = 0;
}
SYS_INT_SourceEnable(INT_SOURCE_USART_1_TRANSMIT);
break;

case INT_SOURCE_USART_1_ERROR:
err = PLIB_USART_ErrorsGet(USART_ID_1);
SYS_PRINT("ERROR:^%d\r\n",err);
PLIB_USART_ReceiverOverrunErrorClear(USART_ID_1);
//SYS_INT_SourceEnable(INT_SOURCE_USART_1_ERROR);
break;

case INT_SOURCE_USART_1_RECEIVE:

usart_value = PLIB_USART_ReceiverByteReceive(USART_ID_1);
SYS_PRINT("-%d\r\n",usart_value);
//usart_recv_isr(0);

if(PLIB_USART_ReceiverOverrunHasOccurred(USART_ID_1))
{
PLIB_USART_ReceiverOverrunErrorClear(USART_ID_1);
}
PLIB_USART_TransmitterEnable(USART_ID_1);//wuhao
//SYS_INT_SourceEnable(INT_SOURCE_USART_1_RECEIVE);
break;
default:
SYS_MESSAGE("default\r\n");
break;
}
}
 
Thanks 
#1

1 Reply Related Threads

    Paul PortSol
    Super Member
    • Total Posts : 484
    • Reward points : 0
    • Joined: 2015/07/03 11:52:03
    • Location: Newfoundland, Canada
    • Status: offline
    Re: PIC32MX775f256h usart problem with HV2.06 2019/09/03 01:51:37 (permalink)
    0
    Try turning off error interrupts, they had issues in some Harmony Versions.
    Better is your protocol handle errors with checksums and packet framing (bytewise error checking can easily pass double bit errors).
    Paul
     
    #2
    Jump to:
    © 2019 APG vNext Commercial Version 4.5