Hello,
I have just started playing with USB communication with the MSP-EXP430F5529LP launchpad. I wrote a very simple program to receive three 'serial' bytes, but I'm not getting the behavior I expected.
The starting point for my code was the 'C4_PacketProtocol' example (which works fine). My version is much simpler. I changed the initial receiveData function to receive three bytes (instead of just one) and then it just polls for the bDataReceiveCompleted_event flag, which is set inside USBCDC_handleReceiveCompleted per the original example. The example is a state machine that receives packets, but this version simply stops once the bDataReceiveCompleted flag is set.
When I run the code, execution gets to the while loop that polls for bDataReceiveCompleted, but it is never set to TRUE. Just like the example, this flag is set in the USBCDC_handleReceiveCompleted event handler (the event handler or its code were not modified). I do know other events are firing, since the code moves out of LPM0 and into the while loop.
Also, USBCDC_getInterfaceStatus is returning 0x04 (USBCDC_DATA_WAITING) and USBCDC_getBytesInUSBBuffer returns the number of bytes I sent, so the data is there - but for some reason I can't get the USBCDC_hangleReceiveCompleted to trigger.
I've gone through the API documentation a few times, but I'm obviously still missing a key concept here...any ideas?
Thanks!
_______________
#include "hal.h" // Global flags set by events volatile uint8_t bDataReceiveCompleted_event = FALSE; // from USBCDC_handleReceiveCompleted in usbEventHandling.c volatile uint8_t bCommandBeingProcessed = FALSE; // // Application globals uint16_t x,y; uint8_t size; char c[2] = ""; // The "size" byte can only be a single ASCII numerical digit, which means 1-9 #define bufferLen 11 uint8_t buffer[bufferLen]; char outString[65]; // Holds outgoing strings to be sent uint16_t packetSize; // Packet Size - can be anywhere from 1-65535 bytes but for now set to a char void main (void) { volatile uint8_t status; volatile uint8_t bytesatPort; WDT_A_hold(WDT_A_BASE); // Stop watchdog timer // Minumum Vcore setting required for the USB API is PMM_CORE_LEVEL_2 . PMM_setVCore(PMM_CORE_LEVEL_2); USBHAL_initPorts(); // Config GPIOS for low-power (output low) USBHAL_initClocks(8000000); // Config clocks. MCLK=SMCLK=FLL=8MHz; ACLK=REFO=32kHz USB_setup(TRUE, TRUE); // Init USB & events; if a host is present, connect __enable_interrupt(); // Enable interrupts globally while (1) { // Check the USB state and directly main loop accordingly switch (USB_getConnectionState()) { // This case is executed while your device is enumerated on the // USB host case ST_ENUM_ACTIVE: // If no command is being processed, then open to receive the // start of the "packet" GPIO_setOutputLowOnPin(LED_PORT4,LED_PIN7); // Turn OFF green LED // Only open it if we haven't already done so if (!(USBCDC_getInterfaceStatus(CDC0_INTFNUM,&x,&y) & USBCDC_WAITING_FOR_RECEIVE)) { GPIO_setOutputHighOnPin(LED_PORT4,LED_PIN7); // Turn on green LED if we go into waiting for receive // Start a receive operation for three bytes, which will be the start of frame and the size byte. if (USBCDC_receiveData(buffer,3,CDC0_INTFNUM) == USBCDC_BUS_NOT_AVAILABLE) { // Abort receive is BUS is not avialble GPIO_setOutputLowOnPin(LED_PORT4, LED_PIN7); __delay_cycles(1000000); USBCDC_abortReceive(&x,CDC0_INTFNUM); break; } // GPIO_setOutputHighOnPin(LED_PORT, LED_PIN); } __bis_SR_register(LPM0_bits + GIE); // go to sleep until event triggers while (!bDataReceiveCompleted_event) // Wait until data is received { GPIO_setOutputHighOnPin(LED_PORT,LED_PIN); // blink the Red LED __delay_cycles(1000000); GPIO_setOutputLowOnPin(LED_PORT,LED_PIN); __delay_cycles(1000000); status = USBCDC_getInterfaceStatus(CDC0_INTFNUM,&x,&y); bytesatPort = USBCDC_getBytesInUSBBuffer(CDC0_INTFNUM); } GPIO_setOutputLowOnPin(LED_PORT4,LED_PIN7); // Turn Off Green LED while(1); // wait here