开发者

SPI on Arduino with HID reader

开发者 https://www.devze.com 2023-02-18 11:40 出处:网络
I\'m building a project that uses an HID OEM75 as the access point for a locking mechanism.We\'re doing our control through an Arduino Duemilanove (ATmega328).We\'re working with SPI for the security

I'm building a project that uses an HID OEM75 as the access point for a locking mechanism. We're doing our control through an Arduino Duemilanove (ATmega328). We're working with SPI for the security and (apparently) support. (I realize that any RFID chip has pretty weak security.)

I'm currently struggling with receiving bytes via SPI from the card reader.

The card reader is in autonomous read mode, meaning it reads a card, sends a signal to the Arduino (via a card present line, separate from SPI), which tells the Arduino to pull the Slave Select line high to activate the transfer cycle from the card reader. This is wher开发者_JS百科e I run into trouble, I can't understand how I can get the Arduino to simply read the bytes coming in from the card reader without sending any command bytes to the card reader?

The default command structure, SPI.transfer(0x00), sends a byte (in this case the dummy byte 0x00) and then accepts a byte from the source, but because our source is operating autonomously, it won't accept the dummy byte (and that will actually mess up its operation).

To word it simply: how can we accept a string of bytes from the slave source without sending bytes from the Master Source, using Arduino's SPI library?


If I am not wrong, using the SPI bus as a master is like shifting a dummy byte to the slave while reading the incoming byte in reverse.

  • USB HID Host driver for Windows from embedded24.net


Well it's a little late, but hey, it'll help someone out there.

First off:

which tells the Arduino to pull the Slave Select line high to activate the transfer cycle from the card reader.

This is SPI, you pull the Slave Select low to activate the slave, not high. You put it high to tell it to shut up while others are talking.

I can't understand how I can get the Arduino to simply read the bytes coming in from the card reader without sending any command bytes to the card reader?

That's because you don't. In SPI, the master (which the arduino is set up as and the SPI.h library assumes) initiates communication. It sends out data on the MOSI line and the slave responds on the MISO line. If you have nothing to say to the slave, just send 0xFF or whatever dummy bytes and then check what came in on the MISO. On the arduino, I believe that gets stored in the SPDR, SPI data register. Or use whatever the spi library gives you.

but because our source is operating autonomously, it won't accept the dummy byte (and that will actually mess up its operation).

If the case is that you really can't send data to the SPI slave device without it screwing up, then it's not actually implementing SPI, and the arduino SPI library won't help you. You'll have to hack out your own solution. The SPI standard is actually pretty loose and all sorts of people do it their own special way. Which is vastly annoying. I've seen devices use the SS line to initiate clock synching. Which means you can't just tie it to ground to have that slave always be on.

Before you write it off though, I'd suggest investigating why it won't accept the dummy byte. You might be using "3-wire" SPI which combine MOSI and MISO and turn it from full duplex into half duplex, and you'll have to get the timing right so you don't trample everything.

When getting into the nitty gritty of SPI, an oscilloscope works wonders for seeing what actually happened vs what you think should have happened.

0

精彩评论

暂无评论...
验证码 换一张
取 消