chipKIT® Development Platform

Inspired by Arduino™

UART INTERRUPT

Created Tue, 03 Apr 2012 15:17:17 +0000 by Mathieu2


Mathieu2

Tue, 03 Apr 2012 15:17:17 +0000

Helloo ,

Can some one explain me how to configure UART Interrupt (RX ) on pic32MX795F512L ( ChipKitMAX32 );

In ChipKit Max32 RX1 and TX1 use UART4 on pic32MX795F512L; I need to use RX1 interrupt; (Why all exemples on the net for uart Interrupt for pic32 familly are using UART1 and UART2 , not UART3 or UART4 for exemple? is this mean that pi32 familly don't use other UART Interrupts unlless on UART1 and UART2 ? )

I looked over all examples in this site, and what I understand drive me to this code and compiling give this error:

ERROR after compile :

INT_29_03.cpp: In function 'void IntUart4Handler()':

INT_29_03.cpp:54:4: error: expected ')' before '{' token

CODE IS : #include <plib.h>

volatile int Inter = 0 ; volatile int flag_RX1 = 0 ;

void Config_INT_U4_RX(void) { noInterrupts();

INTEnable(INT_U4RX, INT_ENABLED) ;

INTSetVectorPriority(INT_UART_ 4_VECTOR, INT_PRIORITY_LEVEL_4);

INTSetVectorSubPriority(INT_UA RT_4_VECTOR, INT_SUB_PRIORITY_LEVEL_2);

INTConfigureSystem(INT_SYSTEM_ CONFIG_MULT_VECTOR);

// INTEnableInterrupts(); interrupts(); // VALIDATION INTERRUTION GENERALES }

void setup() {

Serial.begin(38400); Serial1.begin(38400); //pinMode (13,OUTPUT);

Config_INT_U4_RX(); // Activation Interruption RX sur UART4 = U1BRX-UART1B sur pic32MX795F512L = RX1 sur CHIPKIT MAX32

Serial.println(" !!!!!!!!!!!!!!UART4 RX INTERRUPT TEST!!!!!!!!!!!!!!!!!"); }

void __ISR( _UART_4_VECTOR , INT_PRIORITY_LEVEL_42 ) IntUart4Handler(void) { noInterrupts();

if (INTGetFlag(INT_U4RX)) { INTClearFlag(INT_U4RX);

Inter = Serial1.read(); flag_RX1 = 1 ; }

// We don't care about TX interrupt if ( INTGetFlag(INT_U4RX) { INTClearFlag(INT_U4RX); } interrupts(); // VALIDATION INTERRUTION GENERALES }

void loop() { delay(1000);

if (flag_RX1 == 1 ) // SI INTERRUPTION A EU LIE { Serial.println(" "); Serial.write(Inter ); }

Serial.println("" );

flag_RX1 = 0 ; }


Ryan K

Tue, 03 Apr 2012 18:41:33 +0000

Hello,

The reason why the examples don't use UART3 and UART4 I believe is that they don't exist on most of the PIC chips. Both the PIC32MX460F512L and the PIC32MX320F128H (The other two PICs on the other boards in the chipkit/cerebot line) both only have two UART controllers.

As for your ISR you're going to have to encapsulate it in a

extern "C" {
}

section. Also your interrupt priority level is weird. If you wanted priority level two you can change that to ipl2. By the way there are a lot of syntactical errors in that code you posted. I don't think it copied properly to your post.

Best Regards, Ryan K Digilent


Mathieu2

Wed, 04 Apr 2012 09:34:53 +0000

Hello Ryan K, thx for your answer ,

Tthe only erro I can see is for priority your are right I must use ipl2 for level 2 or ipl4 for level 4 ( I'm using ipl4 )

I can't see where is the syntaxical errors, can you show me that plz ?

Thx


Ryan K

Wed, 04 Apr 2012 22:40:20 +0000

Hello,

Like there is a space between the A and the R here:

(INT_UA RT_4_VECTOR

There is a missing closing parenthesis

if ( INTGetFlag(INT_U4RX)

and a few similar things.

Best Regards, Ryan K Digilent


Mathieu2

Thu, 05 Apr 2012 12:16:44 +0000

Heloo

for syntactical errors in the code I did'nt just copied it properly; I tried to use UART2 ( TX2 and RX2 on ChipKitMax32) in hope to use lib.h fonction which I think wase coded for UART1 and UART2 only. My code compile well , but My RX interrupt doese'nt work

( but when I ty to encapslate " ConfigIntUART2(config) " with extern "C" , it does'nt compile and give thise error :

INT_04_04.cpp: In function 'void setup()':
INT_04_04.cpp:26:9: error: expected unqualified-id before string constant

CODE ( this code compile without errors, but RX Interrupt still does'nt work) :

void setup() {

Serial.begin(38400); Serial1.begin(38400); Serial2.begin(38400); //pinMode (13,OUTPUT);

noInterrupts(); // desactive (bloque) toutes les Interruption

/*Configuration (validation ) Interruption sur UART2 */ //extern "C" { ConfigIntUART2(UART_RX_INT_EN | UART_TX_INT_DIS | UART_ERR_INT_DIS | UART_INT_PR0 | UART_INT_SUB_PR0); //}

interrupts(); // Valide (laisse passer ) les interruption validées

Serial.println(" !!!!!!!!!!!!!!UART4 RX INTERRUPT TEST!!!!!!!!!!!!!!!!!"); }

extern "C" { void __ISR(_UART_2_VECTOR,IPL2) Routine_IntUART2(void)
{ DisableIntU2RX; // desactive Interruption RX UART2

INTClearFlag(INT_U2RX); // Efface flag Interruption RX UART2

Inter = Inter + 100 ; // Serial1.read(); flag_RX1 = 1 ;

EnableIntU2RX; // valide Interruption RX UART2
} }

void loop() { delay(1000);

if (flag_RX1 == 1 ) // SI INTERRUPTION A EU LIE }

thanks.