USART issue with AT90USB1287

154 views
Skip to first unread message

Tim Pope

unread,
Jan 29, 2012, 12:31:42 PM1/29/12
to LUFA Library Support List
I'm working on my first AVR project, which in simplified terms will
basically be talking to a canon dslr over the UART (AVR receives
command on usart and translates that into the relevant PTP/PIMA
command). I've dived right into the deep end for my first project and
have already hit a roadblock.

So I've taken the StillImageHost demo and added some ring buffer code
and tried to set the usart to be interrupt driven and my ISR routine
never appears to be called.. i've checked over the datasheet to make
sure i'm setting the right registers and have googled the issue to no
avail.

you can see in my source below the usart is setup by the LUFA
Serial_init function in SetupHardware(), below that I enable the
receive complete interrupt for it (Serial_CreateStream is called at
the end of this function as it was in the demo code already). sei()
gets called in main function after this. I then have my ISR function
at the bottom that is supposed to echo the char and then output the
hexstring of the char (just for me to do some debugging).

As far as I can tell the ISR function is never being called as I never
receive the puts_P(PSTR("Interrupt\r\n")); message.

Any ideas?

Appreciate the help

Regards

Tim

=================================================================
#include "StillImageHost.h"
#include "ring.h"

/** LUFA Still Image Class driver interface configuration and state
information. This structure is
* passed to all Still Image Class driver functions, so that multiple
instances of the same class
* within a device can be differentiated from one another.
*/
USB_ClassInfo_SI_Host_t DigitalCamera_SI_Interface =
{
.Config =
{
.DataINPipeNumber = 1,
.DataINPipeDoubleBank = false,

.DataOUTPipeNumber = 2,
.DataOUTPipeDoubleBank = false,

.EventsPipeNumber = 3,
.EventsPipeDoubleBank = false,
},
};

static uint8_t rxRingAry[BUFFER_SIZE];
ring_t rxRing;

/** Main program entry point. This routine configures the hardware
required by the application, then
* enters a loop to run the application tasks in sequence.
*/
int main(void)
{
SetupHardware();

ring_init(&rxRing, rxRingAry, BUFFER_SIZE);

puts_P(PSTR(ESC_FG_CYAN "Still Image Host Demo running.\r\n"
ESC_FG_WHITE));

LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
sei();

for (;;)
{
StillImageHost_Task();

SI_Host_USBTask(&DigitalCamera_SI_Interface);
USB_USBTask();
}
}

/** Configures the board hardware and chip peripherals for the demo's
functionality. */
void SetupHardware(void)
{
/* Disable watchdog if enabled by bootloader/fuses */
MCUSR &= ~(1 << WDRF);
wdt_disable();

/* Disable clock division */
clock_prescale_set(clock_div_1);

/* Hardware Initialization */
Serial_Init(9600, false);

UCSR1B |= (1 << RXCIE1); // Enable the USART Receive Complete
interrupt (USART_RXC)

LEDs_Init();
USB_Init();

/* Create a stdio stream for the serial port for stdin and stdout */
Serial_CreateStream(NULL);
}

void StillImageHost_Task(void)
{<removed code for easy reading>}

void EVENT_USB_Host_DeviceAttached(void)
{<removed code for easy reading>}

void EVENT_USB_Host_DeviceUnattached(void)
{<removed code for easy reading>}

void EVENT_USB_Host_DeviceEnumerationComplete(void)
{<removed code for easy reading>}

void EVENT_USB_Host_HostError(const uint8_t ErrorCode)
{<removed code for easy reading>}

void EVENT_USB_Host_DeviceEnumerationFailed(const uint8_t ErrorCode,
const uint8_t
SubErrorCode)
{<removed code for easy reading>}

ISR(USART1_RX_vect)
{
char recievedByte;
puts_P(PSTR("Interrupt\r\n"));
recievedByte = Serial_ReceiveByte();
Serial_SendByte(recievedByte);
printf_P(PSTR(ESC_FG_RED " %x" ESC_FG_WHITE), recievedByte);
ring_add(&rxRing, recievedByte);
}

Tim Pope

unread,
Feb 4, 2012, 1:31:35 PM2/4/12
to lufa-s...@googlegroups.com
So to put the resolution to this for future users...

User Opendous replied:

 You should not put such time-intensive functions in an interruptservice routine. Start by modifying the StillImage firmware to create a very simpleUART loopback not interacting with USB.  Then add in the PTP translation.  Use the USBtoSerial demo for guidance. http://code.google.com/p/lufa-lib/source/browse/trunk/Projects/USBtoSerial/USBtoSerial.c

He was right on the money (I had read that before but somehow it slipped my mind), so I simply modified my code to toggle the LED's as a test like so and everything worked fine:

ISR(USART1_RX_vect)

{

char recievedByte;

recievedByte = Serial_ReceiveByte();

ring_add(&rxRing, recievedByte);

LEDs_ToggleLEDs(LEDMASK_USB_ERROR);

//Enter has been sent so process command

if (0x0D == recievedByte)

{

LEDs_ToggleLEDs(LEDMASK_USB_READY);

}

}

Reply all
Reply to author
Forward
0 new messages