[En-Nut-Discussion] Receive-Interrupt with the Debug-Unit

Markus Dost markus.dost at dr-clauss.de
Fri Oct 19 15:11:39 CEST 2012


Hi again,

I want to use the Debug-Unit of my EIR as a UART to receive chars by 
interrupt with this piece of code:

#include <compiler.h>
#include <dev/board.h>
#include <sys/timer.h>

static void RS232_Receive(void *arg){
	uint32_t csr = inr(DBGU_SR);
	
	if(csr & US_RXRDY)
		uint8_t Buffer8 = inr(DBGU_RHR);		// read out the char
}	

int main(void){	
	uint32_t RS232_Baud = 115200;

	NutRegisterSysIrqHandler(&syssig_DBGU, RS232_Receive, 0);	// Register DEBUG-UNIT interrupt handler.
	outr(PMC_PCER, _BV(SYSC_ID));						// Enable DEBUG-UNIT
	outr(PIOA_PDR, _BV(9) | _BV(10));					// Disable GPIO on UART tx/rx pins
	outr(DBGU_CR, US_RSTRX | US_RSTTX | US_RXDIS | US_TXDIS);	// Reset UART
	outr(DBGU_IDR, 0xFFFFFFFF);							// Disable all interrupts
	outr(DBGU_BRGR, (NutGetCpuClock() / (8 * RS232_Baud) + 1)/2 );	// Set UART baud rate generator register
	outr (DBGU_MR, US_CHMODE_NORMAL | US_PAR_NO);		// Set UART mode to 8 data bits, no parity and 1 stop bit

	outr(DBGU_CR, US_RXEN | US_TXEN);					// Enable UART receiver and transmitter
	outr(DBGU_IER, US_RXRDY);							// Enable receiver interrupts
	NutSysIrqEnable(&syssig_DBGU);						// enable the interrupt-source
	
	for(;;);
	return 0;
}

When I try this app, the UART receives the sended characters but the 
program doesn't go to the interrupt handler to read out the char. Did I 
made a mistake with the registration of the handler or is the interrupt 
source not enabled correctly?

Best regards,
Markus
-------------- next part --------------
#include <compiler.h>
#include <dev/board.h>
#include <sys/timer.h>

static void RS232_Receive(void *arg){
	uint32_t csr = inr(DBGU_SR);
	
	if(csr & US_RXRDY)
		uint8_t Buffer8 = inr(DBGU_RHR);
}	

int main(void){	
	uint32_t RS232_Baud = 115200;

	NutRegisterSysIrqHandler(&syssig_DBGU, RS232_Receive, 0);	// Register DEBUG-UNIT interrupt handler.
	outr(PMC_PCER, _BV(SYSC_ID));						// Enable DEBUG-UNIT
	outr(PIOA_PDR, _BV(9) | _BV(10));					// Disable GPIO on UART tx/rx pins
	outr(DBGU_CR, US_RSTRX | US_RSTTX | US_RXDIS | US_TXDIS);	// Reset UART
	outr(DBGU_IDR, 0xFFFFFFFF);							// Disable all interrupts
	outr(DBGU_BRGR, (NutGetCpuClock() / (8 * RS232_Baud) + 1)/2 );	// Set UART baud rate generator register
	outr (DBGU_MR, US_CHMODE_NORMAL | US_PAR_NO);		// Set UART mode to 8 data bits, no parity and 1 stop bit

	outr(DBGU_CR, US_RXEN | US_TXEN);					// Enable UART receiver and transmitter
	outr(DBGU_IER, US_RXRDY);							// Enable receiver interrupts
	NutSysIrqEnable(&syssig_DBGU);						// enable the interrupt-source
	
	for(;;);
	return 0;
}



More information about the En-Nut-Discussion mailing list