Hot!How to receive data from Barcode Scanner (Reader) ?

Page: < 123 Showing page 3 of 3
Author
rodims
Super Member
  • Total Posts : 1377
  • Reward points : 0
  • Joined: 2009/02/10 11:08:59
  • Location: 51.9627, 7.6262
  • Status: offline
Re: How to receive data from Barcode Scanner (Reader) ? 2018/06/07 07:40:47 (permalink)
0
You cannot edit / save your post, once you have an URL inside (your PDF link), which was already saved. 
Unlink the URL and then it is possible to save your changes. It will be automatically linked again. (still problems will occur, when your link is long and was shortened, then you have to reenter)
 
It will not be really possible for anyone but you to verify your changes with buffer-bypass etc. This could introduce new wiring problems. E.g. you cannot bypass the HC125 without cutting some PCB tracks, not sure how you did that.  And probably it was not necessary.
 
I think you simply need to start "measuring" the SPI signals and the voltages. 
Assuming that you now try to set one of the MAX3421E output ports by a single SPI write (use the alternate logic level which is not on that output after reset; or toggle it slowly), I see the following possibilities for failure.

a) even if you have experience with SPI, you need to have SPI working in exactly that PIC and configuration with another SPI device, before you can assume the firmware would be ok on behalf of the PIC
b) The wiring to your Arduino device could be wrong
c) Power configuration of this Arduino board could be wrong. In general I would assume that they try to allow both 3.3 V and 5 V, because there are Arduino Boards with either voltage.
 
I think there a currently too many possible sources for your problem. 
Therefore I would measure all these signals and voltage directly at the MAX3421E chip pins. 
Voltage, SPI Clock, SDO (out from PIC), and SS, which you already checked.
Ideally you have a logic analyzer or scope. E.g. write 0x55 to the MAX3421E outputs, that would be testable even with a scope.
 
 
#41
softlab
Super Member
  • Total Posts : 290
  • Reward points : 0
  • Joined: 2011/03/30 09:26:30
  • Location: 0
  • Status: offline
Re: How to receive data from Barcode Scanner (Reader) ? 2018/06/08 08:25:01 (permalink)
0
Ok. let me test and update you.
thank you.
#42
GilJ
Super Member
  • Total Posts : 105
  • Reward points : 0
  • Joined: 2011/04/05 02:36:47
  • Location: 0
  • Status: offline
Re: How to receive data from Barcode Scanner (Reader) ? 2018/06/09 11:51:05 (permalink)
0
Why have they used Buffer on the board? One Buffer's [MOSI, RESET, SCK] VCC is +3.3V and another Buffer's [INT & MISO] VCC is +5V.

Those buffers are for logic level translation 3.3/5 V. Since you are running the MAX3421E and PIC16 at 3.3V bypassing them is a good thing. The USB host shield SJ1 to SJ6 pads seem to allow just that.

I would try to use just the code for the usb host on the PIC16. The full code if it fits. I understand you don't have much space available. I would make a new test project just for USB host. If it would work only then I would customize it and see if it would fit on the main project.

The code you mentioned is for C18, PIC18. Did you compile it for the PIC16 without changing much?

At startup, did you initialize with MAX3421E_init() and USB_init()? At your main loop do you call MAX3421E_Task() and USB_Task()? Any delays on the main loop?
 
#43
softlab
Super Member
  • Total Posts : 290
  • Reward points : 0
  • Joined: 2011/03/30 09:26:30
  • Location: 0
  • Status: offline
Re: How to receive data from Barcode Scanner (Reader) ? 2018/06/14 03:53:41 (permalink)
+1 (1)

*** Now I can able to talk to USB Scanner and output seen on the HyperTerminal. (RESULT ATTACHED)
 
a) even if you have experience with SPI, you need to have SPI working in exactly that PIC and configuration with another SPI device, before you can assume the firmware would be ok on behalf of the PIC

 
You are absolutely correct. I thought we have to send "1" with "reg" address as (reg | 0x80) for all SPI write, "Even after I read the MAX3421E datasheet", my carelessness !. Thanks for pinpoint the core issue of the problem.
 
I have changed the RES (MAX3421E reset) button circuit.
Removed both the HC74125D BUFFER ICs and connected all pins directly to PIC MCU.
I changed SPI write code (reg + 0x02); SPI read as usual (reg). - thanks to rodims !
 
Now I can able to talk to USB Scanner successfully and output seen on the HyperTerminal.
But still, one more issue to be solved. A problem in receiving barcode value from the scanner to PIC MCU. I tried both interrupt & polling method. None works.
PIC MCU
RB0 INTERRUPT SET
PEIE SET
GIE SET
 
MAX3421E
REMOTE WAKE-UP SIGNAL IE SET, RECEIVE DATA AVAILABLE IE SET
IE SET AT MAX3421E

void interrupt isr(){
   if(~RB0){
      test = 1;
   }
}
void main(){
   INTCON = 0;
   PORTA = 0X00;
   PORTB = 0X00;
   PORTC = 0X00;
   TRISA = 0X00;
   TRISB = 0X00;
   TRISC = 0X00;
   ANSELA = 0X00;
   ANSELB = 0X00;
   TRISB0 = 1; // RB0 INPUT
   INTEDG = 0; // LOW EDGE DETECT
   nWPUEN = 0; // indi pull-up
   INTE = 1;
   INTF = 0;
   PEIE = 1;
   GIE = 1;
   MAXreg_wr(rPINCTL,(bmFDUPSPI|bmINTLEVEL));
   ... // RESET MAX3421E
   ... // PLL STABILIZE TIME
   ...
   ...
   // ENABLE RECEIVE DATA & RWUP IE
   MAXreg_wr(rHIEN,(bmRCVDAVIE|bmRWUIE));
   // ENABLE IE ON INT PIN
   MAXreg_wr(rCPUCTL, bmIE);
   // clear the RECEIVE DATA & REMOTE WAKE-UP IRQ
   MAXreg_wr(rHIRQ,(bmRCVDAVIRQ|bmRWUIRQ));
   detect_device();
   waitframes(200); // Some devices require this
   enumerate_device();
   wait_for_disconnect();
   while(1){
   }
}

 
Now, When I read the barcodes, the scanner correctly reads, but no data received from the scanner to PIC MCU. No interrupt occurred on INT PIN (RB0). INT pin does not go LOW after reading the barcode. It stays at +3.26V.
 
On board, MAX3421E INT pin pulled up to +3.3V thru' 2.2K resistor as mentioned in the datasheet.
 
The code you mentioned is for C18, PIC18. Did you compile it for the PIC16 without changing much?

I have used the sample code from both MAXIM WEBSITE (MAX3421E) provided for keil-C and the URL that I posted (PIC18F code - circuitathome.com). I have modified the code according to PIC16F.
 
Any help?
 
Thank you all.
#44
softlab
Super Member
  • Total Posts : 290
  • Reward points : 0
  • Joined: 2011/03/30 09:26:30
  • Location: 0
  • Status: offline
Re: How to receive data from Barcode Scanner (Reader) ? 2018/06/14 03:57:32 (permalink)
0
attachments:

Attached Image(s)

#45
softlab
Super Member
  • Total Posts : 290
  • Reward points : 0
  • Joined: 2011/03/30 09:26:30
  • Location: 0
  • Status: offline
Re: How to receive data from Barcode Scanner (Reader) ? 2018/06/14 04:00:40 (permalink)
0
Remaining attachments:

Attached Image(s)

#46
DarioG
Allmächtig.
  • Total Posts : 54081
  • Reward points : 0
  • Joined: 2006/02/25 08:58:22
  • Location: Oesterreich
  • Status: offline
Re: How to receive data from Barcode Scanner (Reader) ? 2018/06/14 04:15:39 (permalink)
+1 (1)
Write to LATx, not PORTx Smile

GENOVA :D :D ! GODO
#47
softlab
Super Member
  • Total Posts : 290
  • Reward points : 0
  • Joined: 2011/03/30 09:26:30
  • Location: 0
  • Status: offline
Re: How to receive data from Barcode Scanner (Reader) ? 2018/06/14 04:27:13 (permalink)
0
Write to LATx, not PORTx

Yes. I have already written in the code.
LATA = 0b00000000;
LATB = 0b00000000;
LATC = 0b00000000;
LATE = 0b00000000;
 
thank you
#48
DarioG
Allmächtig.
  • Total Posts : 54081
  • Reward points : 0
  • Joined: 2006/02/25 08:58:22
  • Location: Oesterreich
  • Status: offline
Re: How to receive data from Barcode Scanner (Reader) ? 2018/06/14 04:36:53 (permalink)
+1 (1)
Ah ok, because in your code above I could see things like PORTA = 0x00 - in case, you can remove those because writing to LATx transparently also writes to PORT

GENOVA :D :D ! GODO
#49
rodims
Super Member
  • Total Posts : 1377
  • Reward points : 0
  • Joined: 2009/02/10 11:08:59
  • Location: 51.9627, 7.6262
  • Status: offline
Re: How to receive data from Barcode Scanner (Reader) ? 2018/06/14 06:47:05 (permalink)
0
I changed SPI write code (reg + 0x02); SPI read as usual (reg)
...
Now I can able to talk to USB Scanner successfully and output seen on the HyperTerminal.

 
Yes Bit 1  (0x02) in the command bytes is used as DIR bit (read or write).
I'm not sure, what you mean by "I can write to the USB Scanner", I assume you meant "I can write to the MAX3421E"?
I do not see the definitions (registers and value) for these various parameters of MAXreg_wr function.
 // ENABLE RECEIVE DATA & RWUP IE
   MAXreg_wr(rHIEN,(bmRCVDAVIE|bmRWUIE));
   // ENABLE IE ON INT PIN
   MAXreg_wr(rCPUCTL, bmIE);
   // clear the RECEIVE DATA & REMOTE WAKE-UP IRQ
   MAXreg_wr(rHIRQ,(bmRCVDAVIRQ|bmRWUIRQ));

Since you have read the manuals paragraph about the INT configuration and have the pull up in place. 
Did you ensure that you have an INT pulse on that pin (e.g. logic analyzer) or do you just rely on your PIC code ?
(which means the problem could be either side)
The pulse is rather short (1 ... 10 us configurable, table 4) .
If there is definitely no INT pulse, and in case this problem somehow related to USB functions, then you could test the interrupt also with the GPIN inputs of the MAX3421E.
 
INT can also be configured to assert when any of the general-purpose inputs (GPIN0–GPIN7) are activated (see the GPIN7–GPIN0 section for more details)
 
 
#50
softlab
Super Member
  • Total Posts : 290
  • Reward points : 0
  • Joined: 2011/03/30 09:26:30
  • Location: 0
  • Status: offline
Re: How to receive data from Barcode Scanner (Reader) ? 2018/06/14 08:36:06 (permalink)
0
I do not see the definitions (registers and value) for these various parameters of MAXreg_wr function.
 // ENABLE RECEIVE DATA & RWUP IE
   MAXreg_wr(rHIEN,(bmRCVDAVIE|bmRWUIE));
   // ENABLE IE ON INT PIN
   MAXreg_wr(rCPUCTL, bmIE);
   // clear the RECEIVE DATA & REMOTE WAKE-UP IRQ
   MAXreg_wr(rHIRQ,(bmRCVDAVIRQ|bmRWUIRQ));

REG DETAILS ATTACHED
 
#define rCPUCTL 0x80 //16<<3
/* CPUCTL Bits */
#define bmPUSLEWID1 0x80 //b7
#define bmPULSEWID0 0x40 //b6
#define bmIE 0x01 //b0

 

#define rHIRQ 0xC8 //25<<3
/* HIRQ Bits */
#define bmBUSEVENTIRQ 0x01 // indicates BUS Reset Done or BUS Resume
#define bmRWUIRQ 0x02
#define bmRCVDAVIRQ 0x04
#define bmSNDBAVIRQ 0x08
#define bmSUSDNIRQ 0x10
#define bmCONDETIRQ 0x20
#define bmFRAMEIRQ 0x40
#define bmHXFRDNIRQ 0x80

#define rHIEN 0xD0 //26<<3
/* HIEN Bits */
#define bmBUSEVENTIE 0x01
#define bmRWUIE 0x02
#define bmRCVDAVIE 0x04
#define bmSNDBAVIE 0x08
#define bmSUSDNIE 0x10
#define bmCONDETIE 0x20
#define bmFRAMEIE 0x40
#define bmHXFRDNIE 0x80

 
 
The USB Peripheral, goes to sleep, if the Data Line idle > 3ms. It will send remote wake-up signal to the host if it want to send data to host. The host will wake-up after asserting the interrupts.
In PC, we have to open Notepad or similar editors for receiving data from Barcode Scanner. I don't know how to receive data in PIC. I am studying peripheral mode now. if anyone has any idea please help.
 
thank you.
 

Attached Image(s)

#51
softlab
Super Member
  • Total Posts : 290
  • Reward points : 0
  • Joined: 2011/03/30 09:26:30
  • Location: 0
  • Status: offline
Re: How to receive data from Barcode Scanner (Reader) ? 2018/06/15 05:41:15 (permalink)
0
I can able to write to all MAX3421E registers except HIEN (R26 - HOST INTERRUPTS ENABLE REGISTER). Why?

 
BYTE ien_reg;
MAXreg_wr(rHIEN, 0X02); // RWUP IE
ien_reg = MAXreg_rd(rHIEN);
 

ien_reg always read as 0x00.
all bits are correctly set or clear by MAX3421E (HIRQ Reg) while doing transfers except RWUIRQ.
This could be the last issue that I have to unlock to complete the project.
Any idea?
 
#52
rodims
Super Member
  • Total Posts : 1377
  • Reward points : 0
  • Joined: 2009/02/10 11:08:59
  • Location: 51.9627, 7.6262
  • Status: offline
Re: How to receive data from Barcode Scanner (Reader) ? 2018/06/15 07:18:59 (permalink)
+1 (1)
I would conclude that you are not in
Table 2. MAX3421E Register Map in Host Mode (HOST = 1)
 
but in
Table 1.  MAX3421E Register Map in Peripheral Mode (HOST = 0)
 
which does not support R26, or better, which will always read all 0 .
 
 
post edited by rodims - 2018/06/15 07:26:05
#53
softlab
Super Member
  • Total Posts : 290
  • Reward points : 0
  • Joined: 2011/03/30 09:26:30
  • Location: 0
  • Status: offline
Re: How to receive data from Barcode Scanner (Reader) ? 2018/06/15 07:56:01 (permalink)
0
I would conclude that you are not in
Table 2. MAX3421E Register Map in Host Mode (HOST = 1)
 
but in
Table 1.  MAX3421E Register Map in Peripheral Mode (HOST = 0) 
 
which does not support R26, or better, which will always read all 0 .

Yes. You are correct. I have set host mode = 1 only in the function 

detect_device();

as
MAXreg_wr(rMODE,MODE_FS_HOST); 

Also, I have reset the MAX3421 few times inside the function

 
enumerate_device();
 

So, all registers are reset and I read as zero. Now, I have enabled the RWUIE interrupt and the IE interrupt after the function
enumerate_device();

as

 
MAXreg_wr(rHIEN, 0x02); // RWUP IE
MAXreg_wr(rCPUCTL, 0x01); // ENABLE IE
MAXreg_wr(rHIRQ, bmRWUIRQ); // clear RWUP bit
 
 
 
TRISB0 = 1; // INPUT
nWPUEN = 1; // DISABLE PORTB PULL-UPS
INTEDG = 0; // FALLING EDGE
INTF = 0;
INTE = 1;
PEIE = 1;
GIE = 1;
 

 
Now I can able to set the interrupt. But still, no RWUIRQ interrupt fired while reading barcode label. RB0 (INT) pin always stays at +3.3V.
Any idea?
thank you.
post edited by softlab - 2018/06/15 07:59:43
#54
rodims
Super Member
  • Total Posts : 1377
  • Reward points : 0
  • Joined: 2009/02/10 11:08:59
  • Location: 51.9627, 7.6262
  • Status: offline
Re: How to receive data from Barcode Scanner (Reader) ? 2018/06/15 08:58:47 (permalink)
0
Now I can able to set the interrupt. But still, no RWUIRQ interrupt fired while reading barcode label. RB0 (INT) pin always stays at +3.3V.

 
Did you check this ? (or how do you really test for INT ?)
Did you ensure that you have an INT pulse on that pin (e.g. logic analyzer) or do you just rely on your PIC code ?
(which means the problem could be either side)
The pulse is rather short (1 ... 10 us configurable, table 4) .
 
In PC, we have to open Notepad or similar editors for receiving data from Barcode Scanner. I don't know how to receive data in PIC. I am studying peripheral mode now. if anyone has any idea please help.

 
As said many posts before, the scanner obviously acts as a USB HID Keyboard (HID = human interface device).  So it will just write the text in any open text window which has the focus (e.g. notepad).
 
At some point you will need to write code to handle the interrupt and to receive the data with the PIC, but
I would first check that any of the USBIRQ bits gets active for any scanner action (or even attaching to USB).
You might need to reset the interrupts before. Note that I do not have experience with the MAX3421E, I'm just reading the datasheet. Next step (or in parallel) , check whether your INT output pin behaves as expected.
 
#55
softlab
Super Member
  • Total Posts : 290
  • Reward points : 0
  • Joined: 2011/03/30 09:26:30
  • Location: 0
  • Status: offline
Re: How to receive data from Barcode Scanner (Reader) ? 2018/06/15 09:11:49 (permalink)
0
Did you check this ? (or how do you really test for INT ?)
Did you ensure that you have an INT pulse on that pin (e.g. logic analyzer) or do you just rely on your PIC code ?

I relied on PIC Code.
The pulse is rather short (1 ... 10 us configurable, table 4) .

It is for INTLEVEL = 0 & (POSINT = 0 OR 1)
 
I have used INTLEVEL = 1;
i.e, INT - RB0 pin low when the interrupt occurred and stay low until we clear the interrupt.
 
I would first check that any of the USBIRQ bits gets active for any scanner action (or even attaching to USB).

It detects correctly Scanner when connecting or disconnecting and prints on hyperterminal.
You might need to reset the interrupts before

Yes. I have cleared the RWUIE interrupt.
MAXreg_wr(rHIRQ, bmRWUIRQ); // clear RWUP bit
 
Thank you
 
post edited by softlab - 2018/06/15 09:15:06
#56
rodims
Super Member
  • Total Posts : 1377
  • Reward points : 0
  • Joined: 2009/02/10 11:08:59
  • Location: 51.9627, 7.6262
  • Status: offline
Re: How to receive data from Barcode Scanner (Reader) ? 2018/06/15 10:50:50 (permalink)
0
It detects correctly Scanner when connecting or disconnecting and prints on hyperterminal

I do not understand "prints on hyperterminal". 
Who prints ?
Can I assume your Hyperterminal (Terminal application on the PC) is connected to your PIC's  UART output ?
So what then does "it detects correctly Scanner ..." mean ?
That you already have PIC code which correctly jumps into your ISR as response to the INT from MAX3421E connected to your PIC pin ? And in response your PIC code outputs some info text to the UART ?
 
But when performing a Scan, then no interrupt is generated by MAX3421E ?
 
 
#57
softlab
Super Member
  • Total Posts : 290
  • Reward points : 0
  • Joined: 2011/03/30 09:26:30
  • Location: 0
  • Status: offline
Re: How to receive data from Barcode Scanner (Reader) ? 2018/06/15 12:02:54 (permalink)
0
Can I assume your Hyperterminal (Terminal application on the PC) is connected to your PIC's  UART output ?

Yes.
So what then does "it detects correctly Scanner ..." mean ?

PIC MCU now can send and receive data (descriptors) to/from the Scanner thru' MAX3421E successfully. I already posted this with Hyperterminal Screen Shots.
Now, I am unable to receive only Barcode Value from the Scanner. Scanner correctly reads the barcode and alarm the (good read) beep sound. But no interrupt is generated at PIC MCU. I have tried polling method also (RWUIRQ) but that too not works.
That you already have PIC code which correctly jumps into your ISR as response to the INT from MAX3421E connected to your PIC pin ? And in response your PIC code outputs some info text to the UART ?

Only Polling method is used (Not interrupts). I have enabled interrupts only after successfully enumerated the Scanner.
But when performing a Scan, then no interrupt is generated by MAX3421E ?

Yes.
#58
softlab
Super Member
  • Total Posts : 290
  • Reward points : 0
  • Joined: 2011/03/30 09:26:30
  • Location: 0
  • Status: offline
Re: How to receive data from Barcode Scanner (Reader) ? 2018/06/19 01:43:01 (permalink)
0
Now, all interrupts occurred OK except RSMREQIRQ(RWUIRQ) - Remote Wake Up IRQ interrupt. I read the datasheet. But no success. Does anyone have bar code scanner as peripheral experience?
 
Also, I tried polling IN INTERRUPT request to peripheral every 5ms. No success yet. Actually, this should be done by MAX3421E and wake the MCU if it receives data from peripheral. This is the place I struck.
 
From the descriptors, I received from the barcode Scanner's endpoint details as "IN1- Endpoint INTERRUPT with polling every 5ms" (screenshot is attached). So, I have to send IN request to peripheral (scanner) with endpoint 1. Am I right? 
For example IN_Transfer(0x00, 0x01)
0x00 -> bulk/interrupt type endpoint transfer
0x01 -> Peripheral (scanner) endpoint address.
 
We need to send DATA TOGGLE SENDTOG0/1 when sending data OUT to a peripheral. When send only IN requesting, should we send data toggle(RCVTOG0/1) to Peripheral?
 
thank you,

Attached Image(s)

#59
Page: < 123 Showing page 3 of 3
Jump to:
© 2018 APG vNext Commercial Version 4.5