Usbasp spi

Материал из Toshiba AC100 wiki
Перейти к навигации Перейти к поиску

Intro

USBASP [1] is a Atmega8/Atmega48 based USB to ISP programmer. It can be picked up from Aliexpress for about $1.5 [2].

It is possible to use the USBASP (firmware update is likely needed) to interact with SPI devices.

I implemented a library for the USBASP using libusb. I used the new library with the raspberry pi 2 based software for communication with my device.


USBASP

libusb can be used to control USBASP stick. USB bulk transfer is used. All commands supported by the USBASP can be found in the USBASP firmware sources.

USBASP have TRANSMIT command. This command sends 4 bytes of data on SPI bus. Also USBASP pushes SS pin low (active) during initialization and keeps it in this state before disconnect.


MFRC522

I have a device based on MFRC522 chip that can be connected to an SPI bus. Protocol is simple: 2 bytes command to read ow write registers. Description can be found in the datasheet (it is free and easy to find).

I failed to get it working with my device as is and I had to modify firmware. Modification is simiple. I added a new command (I called it TRANSMIT2) to transmit data in the format MFRC522 understands. The command controls SS pin and sends only two bytes of data.

After update I lost ability to program Atmega chips for some reason. Initial firmware had no ability to set SPI clock, while updated firmware has. Maybe this is a reason. I didn't figure it out.


I implemented usbasp library. This library have interface that compatible with the bcm2835 library (library for SPI communication on the raspberry pi 2). Then I took rpi-rc522 software (based on bcm2835 library) and modified it to utilize my usbasp library.


Links

TODO: add links to the software.