Hello....Im trying to make a magnetic card reader with the Arduino...
The card reader provides the clock...how I do in the arduino to take the clock from the card reader?
Hello....Im trying to make a magnetic card reader with the Arduino...
The card reader provides the clock...how I do in the arduino to take the clock from the card reader?
I'd probably tie the clock line to an interrupt, then sample the data line (and probably the data ready line, if there is one) inside the interrupt handler.
-j
I have been reading about the interrupts but I dont have an clear idea of how it works....Someone can explain it?
thanks
An interrupt is an event, typically an electrical signal change or a timer expiration. Interrupts are handled or serviced by a function known as an interrupt service routine (ISR).
An ISR is mostly like any other function, except it doesn't get called from your code, it gets called by the hardware monitor when its associated event occurs. Whatever code you have running at the time is interrupted, just as if you had made a function call, and resumes execution once the ISR completes (i.e. hits the end or the return statement). ISRs generally should be kept short, because other interrupts may not be serviced while the ISR is running.
In this case, you want to use the clock as an interrupt. Connect that line to one of the two interrupt pins. Check the data sheet for your card reader to see if you want the event, i.e. reading the data line, to happen on the rising edge or the falling edge of that clock signal and set up the interrupt accordingly.
In its simplest form, your ISR would check the data line, save that bit (probably shifting it into some variable), and returning. There's also a bit of overhead to take care of, like setting a flag to indicate how many bits you've ready, or detecting a bad/partial read. The main loop() will probably do the job of watching some sort of timer to make sure to don't get hung up in the case of a partial read.
-j
I found this:
Once a card has been detected (/CLD1 goes low) we can get to the meat of the matter – reading the card number.
The interesting thing about this experiment is that the reader is a synchronous serial device (i.e., it has clock and data
lines), but it provides the clock instead of accepting a clock – so this precludes the use of SHIFTIN. Yes, we're
going to have to manually code the serial input from the reader but as you'll see, it's not difficult (and this code may
be useful later).
If you connect a logic analyzer to the clock and data lines you'll see several clock pulses before any data bits show
up. This is for good reason: it allows the external device to get in sync with the clock pulses and search for what is called the start sentinel. This is a special character that precedes the card number.
I take it from this....
http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/vol8/col/nv148.pdf
But they are using other language...not C/C++
According to the article you wait for the clock line to go low then shift the bit into a variable and wait for the clock to go high. The code is a form of basic and you should be able to get what you need from the text and an idea of what is expected from the code.