Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
walt0x007
PostPosted: Mar 29, 2012 - 01:41 AM
Rookie


Joined: Aug 20, 2009
Posts: 30


Can someone *please* tell me what I'm overlooking here:


Code:



#include <avr32/io.h>
#include "compiler.h"
#include "board.h"
#include "power_clocks_lib.h"
#include "gpio.h"
#include "usart.h"

// comment out whichever channel isn't being used...
//#define TEST_USART         (&AVR32_USART0)
//#define TEST_USART_IRQ      AVR32_USART0_IRQ
#define TEST_USART      (&AVR32_USART1)
#define TEST_USART_IRQ   AVR32_USART1_IRQ

// global vars
int usart_isr_count = 0;
int n = 0;
U8  rxbuff[100];

// USART interrupt service routine
__attribute__((__interrupt__))
static void usart_rx_isr( void )
{
   volatile int rxByte;
   
   usart_isr_count++; // count the interrupts
    rxByte = (TEST_USART->rhr & AVR32_USART_RHR_RXCHR_MASK) >> AVR32_USART_RHR_RXCHR_OFFSET;
   
   rxbuff[n++] = rxByte;
   if(n>99) {
      n = 0; // set a breakpoint here to view buffer
   }
}

int main(void)
{
    pcl_switch_to_osc(PCL_OSC0, FOSC0, OSC0_STARTUP);

    // comment out the two lines to the port not being used below
   static const gpio_map_t USART_GPIO_MAP =
   {
   //{18, 0},   // usart 0 rx mapping
   //{19, 0}    // usart 0 tx mapping
   {24, 0},    // usart 1 rx mapping
   {23, 0}       // usart 1 tx mapping
   };

   // USART options.
   static const usart_options_t USART_OPTIONS =
   {
      .baudrate     = 4800,
      .charlength   = 8,
      .paritytype   = USART_NO_PARITY,
      .stopbits     = USART_1_STOPBIT,
      .channelmode  = USART_NORMAL_CHMODE
   };

   // Assign GPIO to USART.
   gpio_enable_module(USART_GPIO_MAP, sizeof(USART_GPIO_MAP) / sizeof(USART_GPIO_MAP[0]));

   // Disable all interrupts.
    Disable_global_interrupt();
   
   // Initialize interrupt vectors.
    INTC_init_interrupts();
   
   // register interrupt handler
   INTC_register_interrupt(&usart_rx_isr, TEST_USART_IRQ, AVR32_INTC_INT0);

   // Initialize USART in RS232 mode.
   usart_init_rs232(TEST_USART, &USART_OPTIONS, FOSC0);

   TEST_USART->ier = 0x00000001; //AVR32_USART_IER_RXRDY_MASK;

    Enable_global_interrupt();

   while (true); // wait for interrupts on the serial port
}



USART 1 works perfectly, but when configured for USART0, the ISR never triggers...

It seems like the USART_GPIO_MAP would be the issue here but the values used are what I find in the uc3b0256.h

Any insight would be much appreciated!

Thanks in advance,
Walt
 
 View user's profile Send private message  
Reply with quote Back to top
mikech
PostPosted: Mar 29, 2012 - 02:20 AM
Hangaround


Joined: Aug 19, 2003
Posts: 397
Location: Australia

Perhaps the RS232 interface chip connected to USART0 RX is faulty ?
(If you can, on PA18 connect a resistor and LED to VCC and see if it flickers when you send characters into USART0)

You have only enabled the RXRDY interrupt, but the receiver might be getting a BREAK.

Try transmitting something in the while(true); to confirm that the USART is configured ok.



Ahhh., the joys of comms !.
 
 View user's profile Send private message  
Reply with quote Back to top
walt0x007
PostPosted: Mar 29, 2012 - 04:59 AM
Rookie


Joined: Aug 20, 2009
Posts: 30


Thanks for the feedback. I can see the data at the USART RX pin (PB10 in my case (pin 57) - I'm using a UC3B0256 with 64 pins). This signal is a 0 to 3.3 volts coming from a nearby part, so no additional components are needed.

Also, when jump the signal to either one of the other USARTs, the ISR triggers and I can read the data...

It seems the issue must be software, but I don't see where. USART 0 is very similar to USART 2 and 1 and both of them work fine. The I/O view in AVRStudio 5 shows the configuration to look very similar to 1 and 2.

This has been a tricky issue... I have another board to test with and I believe it behaves the same there too... I'll check that again.

Any other thoughts are very welcome.

Regards,
Walt
 
 View user's profile Send private message  
Reply with quote Back to top
mikech
PostPosted: Mar 29, 2012 - 08:18 AM
Hangaround


Joined: Aug 19, 2003
Posts: 397
Location: Australia

In your original example you had Function A on GPIO 18 which is USART0 RX, but your last post says USART RX is on PB10 !, so you need to use Function C on GPIO 42
 
 View user's profile Send private message  
Reply with quote Back to top
walt0x007
PostPosted: Mar 29, 2012 - 04:41 PM
Rookie


Joined: Aug 20, 2009
Posts: 30


Many thanks. I knew it would be something like that but I just wasn't seeing it. I now notice there are only two possible mappings for these Functions per Peripheral which explains why they label things like

AVR32_USART0_RXD_0_0_PIN
AVR32_USART0_RXD_0_1_PIN

even though the PMR is [1:0] for the later and [0:0] for the former... This was confusing me yesterday.

It is working now. Again, many thanks for the tip.

Walt
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits