Atmel 32U2 / LUFA 140302 / CDC Serial receive not working / mattairtech

34 views
Skip to first unread message

John Zitterkopf

unread,
Apr 24, 2022, 3:10:35 AM4/24/22
to LUFA Library Support List
I posted about this problem on the avrfreaks forum and got basically no response. Reposting it here because I don't really have a clue what's going wrong. I did try email the Mattairtech.com owner but didn't get a response. His website seems "iffy" so maybe he's no longer in business.

Back in 2019 I nearly finished a microcontroller design using the ATmega32U2. I had written the code using the Arduino IDE and had a rather rich instruction set communicated over the Serial interface. I ran into some "life getting in the way" things along with some "keep it simple, stupid" ideas which forced me to take the design back to the drawing board in an effort to reduce component count and thereby cost. 

I created Fab D and got the PCB design back from OSHpark and I re-factored the code I already had and attempted to use it. Welp, sometime between 2019 and now I rebuilt my computer and had to re-install windows 10 clean. I still have the code; but now I can't get the Arduino code to work. Specifically the Serial calls work in that I'm able to send data from the device back to the serial port. 

But I'm not able to receive anything from the computer into the device. 

I have the HEX files from the original code; and they do indeed receive/transmit. But newly compiled code doesn't work to receive.

I've even went so far as to install one of the "SerialEvent" demos which also doesn't work. 

I did a clean install of Arduino software and a clean install of the https://www.mattairtech.com/software/arduino/package_MattairTech_index.json
file in board manager. 

Same issue of not being able to receive data from host computer.

Below is my current test code - which I've obviously reduced to bare minimum to show the issue.
 All I get is the blinking LED; which doesn't change frequency and I never get

"Got Input:" 
which would indicate to me that Serial.available() is never returning True.

 Thoughts? Things I can try?

/*
  Serial Event example

 When new serial data arrives, this sketch adds it to a String.
 When a newline is received, the loop prints the string and
 clears it.

 A good test for this is to try it with a GPS receiver
 that sends out NMEA 0183 sentences.

 Created 9 May 2011
 by Tom Igoe

 This example code is in the public domain.

 http://www.arduino.cc/en/Tutorial/SerialEvent

 */

String inputString = "";         // a string to hold incoming data
boolean stringComplete = false;  // whether the string is complete

#define LED_USB            13 /*D13 = PD0*/
#define LED_TOGGLE         PORTD ^= (1<<PD0); /*PD0*/
#define LED_OFF            PORTD |= (1<<PD0);
#define LED_ON             PORTD &= ~(1<<PD0);

#define MySerial Serial

void setup() {
  pinMode(LED_USB, OUTPUT); LED_TOGGLE;
  // initialize serial:
  MySerial.begin(9600);
  // reserve 200 bytes for the inputString:
  inputString.reserve(200);
}

uint16_t lastms = millis();

void loop()
{
  if (! MySerial.available() ) {
    if ((millis() - lastms) > 1000 ) {
      LED_TOGGLE;
      lastms = millis();
      MySerial.print('*');
    }
  } else {
   MySerial.print("\nGot Input: ");
   MySerial.println(MySerial.read());
  }
}

Paul Stoffregen

unread,
Apr 26, 2022, 11:21:18 PM4/26/22
to lufa-s...@googlegroups.com
Not sure how much this helps, but I copied your code into Arduino 1.8.19 with Teensyduino 1.56 added, and uploaded it to a Teensy 2.0 board.  It seems to work fine.  I see a LED on pin 5 slowly blinking (Teensy 2.0 connects AVR PD.0 to pin 5) and '*' characters slowly appear in the Arduino Serial Monitor.  After I type "test" and click Send, the text below is what I get in the Arduino Serial Monitor window.

Can't explain why it's not working for you on other hardware, and not sure what this has to do with LUFA, but at least can confirm your code seems to be correct.


***************
Got Input: 116

Got Input: 101

Got Input: 115

Got Input: 116

Got Input: 10
***********************************
--
You received this message because you are subscribed to the Google Groups "LUFA Library Support List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lufa-support...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lufa-support/b6451e0c-2429-4c8c-848b-c7f2b8153026n%40googlegroups.com.

John Zitterkopf

unread,
Apr 27, 2022, 3:07:04 AM4/27/22
to LUFA Library Support List
Thanks. Helps to know that the code works properly. 
But it still doesn't "receive" anything on the Atmel32u2 design. :(
Not even sure where to start looking for a "Defect".

My assumption is that if there were a hardware issue with the design - I wouldn't get the asterix at all. Also; I'm pretty sure the code download wouldn't work over usb either. 

So I'm forced to think there is some obsure bug in either the Arduino Core or in the compile which breaks "receive" endpoint. 
Reply all
Reply to author
Forward
0 new messages