Problem in data receiving from USB Peripheral to PIC MCU thru' MAX3421E

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

I have to read data from Barcode Scanner (USB type) to PIC Microcontroller. MAX3421E used as a Host. I can enable to communicate with the Barcode Scanner and Enumerated successfully. But after that, I could not able to receive data from the barcode scanner when reading the barcode label. The barcode sends good-read beep when reading barcode label. In the MAX3421E datasheet, it says it will wake the MCU when it receives data from USB Peripheral thru' RWUIRQ (Remote Wake Up) interrupt. But interrupt not fired when reading barcode label. All interrupts work fine except RWUIRQ (i.e RSMREQIRQ).

Barcode Scanner works fine with PC. But we have to open notepad or similar text editor in order to receive the Barcode Value.

What could be the problem?

I have used USB HOST SHIELD FOR ARDUINO MODULE. Because it has MAX3421E on the board.

PIC MCU VCC = +5V

MAX3421E VCC = +3.3V

BARCODE SCANNER = +5V (100mA, BUS Powered), Powered from Seperate +5V Adapter.

Your help would be highly appreciated.

thank you.

0 Likes
6 Replies
KandlaguntaR_36
Moderator
Moderator
Moderator
25 solutions authored 10 solutions authored 5 solutions authored

As said, the device is supposed to send a RWUIRQ

Provide the snippet of the code that triggers the RWUIRQ.

0 Likes
Anonymous
Not applicable

Thank you Srdr.

I have used 3 Methods. 1. INTERRUPT METHOD WITH SUSPEND, 2. POLLING METHOD WITH SUSPEND, 3. POLLING METHOD WITHOUT SUSPEND

Method 1:

// INTERRUPT METHOD WITH SUSPEND

void wait_for_disconnect(void){

     printf("\r\nWaiting for device disconnect \r\n");

     //ENABLE ON MAX3421E INTERRUPTS

     MAXreg_wr(rHIEN, (bmSUSDNIE|bmRWUIE|bmRCVDAVIE|bmCONDETIE));

     MAXreg_wr(rCPUCTL, bmIE);

     // CLR SUSPNDIRQ,RWUIRQ, CONN IRQ

     MAXreg_wr(rHIRQ, (bmSUSDNIRQ|bmCONDETIRQ|bmRWUIRQ|bmRCVDAVIRQ));

     //ENABLE ON MCU INTERRUPTS

     INTF = 0;

     INTE = 1;

     GIE = 1;

     // SUSPEND VBUS BY CLEARING THE BIT SOFKAENB = 0

     MAXreg_wr(rHIRQ, 0xFF); // CLR ALL PENDING IRQ

     MAXreg_wr(rMODE, (MAXreg_rd(rMODE) & ~(1 << 3)) );

     irq_serviced = 0;

     while(!irq_serviced);

     irq_serviced = 0;

     while(!(MAXreg_rd(rMODE), bmSUSDNIRQ)); // WAIT UNTIL SUSPEND COMPLETE

     MAXreg_wr(rHIRQ, 0xFF); // CLR ALL PENDING IRQ

     irq_serviced = 0;

     do{

          while(!irq_serviced);

          irq_serviced = 0;

          if (MAXreg_rd(rHIRQ) & bmCONDETIRQ){

               MAXreg_wr(rHIRQ, bmCONDETIRQ);

          break;

          }

          else if( (MAXreg_rd(rHIRQ) & bmRWUIRQ) || \

                    (MAXreg_rd(rHIRQ) & bmRCVDAVIRQ) ){ // USB PERIPHERAL SENDS SIGNAL

               MAXreg_wr(rHIRQ, bmRWUIRQ|bmRCVDAVIRQ);

               ReceiveBCodeLblValue(); // READ RCV FIFO

          }

     }while(1);

     irq_serviced = 0;

     // DISABLE ALL INTERRUPTS

     INTF = 0;

     INTE = 0;

     GIE = 0; // DISABLE INTERRUPT

     MAXreg_wr(rCPUCTL, 0x00);

     MAXreg_wr(rHIEN, 0x00);

     MAXreg_wr(rMODE,bmDPPULLDN|bmDMPULLDN|bmHOST); // turn off frame markers

     printf("\r\nDevice disconnected \r\n");

     PERIPHERAL_RE_CONNECTED = 1;

}

Method 2:

// POLLING METHOD WITH SUSPEND

void wait_for_disconnect(void){

     printf("\r\nWaiting for device disconnect \r\n");

     MAXreg_wr(rHIRQ, 0xFF); // CLR ALL PENDING IRQ

     // SUSPEND VBUS BY CLEARING THE BIT SOFKAENB = 0

     MAXreg_wr(rMODE, (MAXreg_rd(rMODE) & ~(1 << 3)) );

     while(!(MAXreg_rd(rMODE), bmSUSDNIRQ)); // WAIT UNTIL SUSPEND COMPLETE

     MAXreg_wr(rHIRQ, 0xFF); // CLR ALL PENDING IRQ

     do{// hang until USB IS UNPLUGGED

          if (MAXreg_rd(rHIRQ) & bmCONDETIRQ){ // USB DISCONNECTED?

                    MAXreg_wr(rHIRQ,bmCONDETIRQ);

          break; // YES. USB DISCONNECTED. EXIT.

          }

          if( (MAXreg_rd(rHIRQ) & bmRWUIRQ) || (MAXreg_rd(rHIRQ) & bmRCVDAVIRQ) ){ // USB PERIPHERAL SENDS SIGNAL

               MAXreg_wr(rHIRQ, bmRWUIRQ|bmRCVDAVIRQ);

               ReceiveBCodeLblValue(); // READ RCV FIFO

          }

     }while(1);

     MAXreg_wr(rMODE,bmDPPULLDN|bmDMPULLDN|bmHOST); // turn off frame markers

     printf("\r\nDevice disconnected \r\n");

     PERIPHERAL_RE_CONNECTED = 1;

}

Method 3:

// POLLING METHOD WITHOUT SUSPEND

void wait_for_disconnect(void){

     printf("\r\nWaiting for device disconnect \r\n");

     MAXreg_wr(rHIRQ, 0xFF); // CLR ALL PENDING IRQ

     do{// hang until USB IS UNPLUGGED

          if (MAXreg_rd(rHIRQ) & bmCONDETIRQ){ // USB DISCONNECTED?

               MAXreg_wr(rHIRQ,bmCONDETIRQ);

          break; // YES. USB DISCONNECTED. EXIT.

          }

          if( (MAXreg_rd(rHIRQ) & bmRWUIRQ) || (MAXreg_rd(rHIRQ) & bmRCVDAVIRQ) ){ // USB PERIPHERAL SENDS SIGNAL

               MAXreg_wr(rHIRQ, bmRWUIRQ|bmRCVDAVIRQ);

               ReceiveBCodeLblValue(); // READ RCV FIFO

          }

     }while(1);

     MAXreg_wr(rMODE,bmDPPULLDN|bmDMPULLDN|bmHOST); // turn off frame markers

     printf("\r\nDevice disconnected \r\n");

     PERIPHERAL_RE_CONNECTED = 1;

}

No RWUIRQ fired when reading barcode label. When Scanner disconnected, it correctly fired and exit the loop. Any help?

thank you.

0 Likes
Anonymous
Not applicable

Interrupt routine added:

if(INTF && INTE){ // IF INTERRUPT OCCURRED

     irq_serviced = 1;

  INTF = 0;

}

0 Likes

Hello Kannan,

Please let us know what is the USB Peripheral controller that is being used in your application.

Best regards,

Srinath S

0 Likes
Anonymous
Not applicable

USB Peripheral is Barcode Scanner (HID). MAX3421E as HOST.

0 Likes

Hello Kannan,

Please let know the Cypress part that is used in your application.

Best regards,

Srinath S

0 Likes