From 108253a1167627288a06654fff1f5ce1351a9b00 Mon Sep 17 00:00:00 2001 From: Othmar Gsenger Date: Sun, 27 Jan 2013 16:59:22 +0000 Subject: usb-i2c-sl018 added lufa i2c tests (non working) git-svn-id: https://svn.spreadspace.org/avr/trunk@66 aa12f405-d877-488e-9caf-2d797e2a1cc7 --- usb-i2c-sl018/tuer-rfid.c | 63 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 56 insertions(+), 7 deletions(-) (limited to 'usb-i2c-sl018/tuer-rfid.c') diff --git a/usb-i2c-sl018/tuer-rfid.c b/usb-i2c-sl018/tuer-rfid.c index 4aebb28..e59b65c 100644 --- a/usb-i2c-sl018/tuer-rfid.c +++ b/usb-i2c-sl018/tuer-rfid.c @@ -33,6 +33,29 @@ #include "util.h" #include "led.h" +#include "LUFA/Drivers/Peripheral/TWI.h" + +//const uint8_t SL018_ADDR = B10100000: +const uint8_t SL018_ADDR = 0xa0; +const uint8_t SL018_WRITE = 0; +const uint8_t SL018_READ = 1; +//============================================ +// Command List, preamble + length + command +//============================================ + +const unsigned char SL018CMD_ComSelectCard[] ={1,1}; +const unsigned char SL018CMD_ComLoginSector0[] ={9,2,0+2,0xAA,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}; +const unsigned char SL018CMD_ComReadBlock1[] ={2,3,1+8}; +const unsigned char SL018CMD_ComWriteBlock1[] ={18,4,1+8,0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99,0xAA,0xBB,0xCC,0xDD,0xEE,0xFF}; +const unsigned char SL018CMD_ComIntiPurse1[] ={6,6,1+8,0x78,0x56,0x34,0x12}; +const unsigned char SL018CMD_ComReadPurse1[] ={2,5,1+8}; +const unsigned char SL018CMD_ComIncrPurse1[] ={6,8,1+8,0x02,0x00,0x00,0x00}; +const unsigned char SL018CMD_ComDecrPurse1[] ={6,9,1+8,0x01,0x00,0x00,0x00}; +const unsigned char SL018CMD_ComCopyValue[] ={3,0x0A,1+8,2+8}; +const unsigned char SL018CMD_ComReadUltralightPage5[] ={2,0x10,0x05}; +const unsigned char SL018CMD_ComWriteUltralightPage5[]={6,0x11,0x05,0x12,0x34,0x56,0x78}; +const unsigned char SL018CMD_ComRedLedOn[] ={2,0x40,1}; +const unsigned char SL018CMD_ComRedLedOff[] ={2,0x40,0}; /* LUFA Library Copyright (C) Dean Camera, 2012. @@ -74,6 +97,24 @@ void EVENT_USB_Device_ControlRequest(void) } /* end LUFA CDC-ACM specific definitions*/ +unsigned char sl018_send_buffer(const unsigned char * buffer) +{ + uint8_t len = 0; + uint8_t pos = 0; + unsigned char ret; + len = buffer[0]; + if (TWI_StartTransmission(SL018_ADDR | SL018_WRITE,10) == TWI_ERROR_NoError) + { + for(pos=0; pos<=len; pos++) + TWI_SendByte(buffer[pos]); + // Must stop transmission afterwards to release the bus + TWI_StopTransmission(); + } else { + return 1; + } + return 0; +} + void handle_cmd(uint8_t cmd) { switch(cmd) { @@ -81,12 +122,19 @@ void handle_cmd(uint8_t cmd) case '1': led_on(); break; case 't': led_toggle(); break; case 'r': reset2bootloader(); break; + case '3': + if(sl018_send_buffer(SL018CMD_ComRedLedOff)) + { + led_toggle(); + } + break; default: CDC_Device_SendString(&VirtualSerial_CDC_Interface, "error\n"); return; } CDC_Device_SendString(&VirtualSerial_CDC_Interface, "ok\n"); } -static void PCint() + +static void PCint(void) { if( (TAG_STA_PIN >> TAG_STA_BIT) & 1) led_on(); @@ -97,12 +145,12 @@ static void PCint() SIGNAL(PCINT0_vect) { PCint(); } -SIGNAL(PCINT1_vect) { - PCint(); -} -SIGNAL(PCINT2_vect) { - PCint(); -} +//SIGNAL(PCINT1_vect) { +// PCint(); +//} +//SIGNAL(PCINT2_vect) { +// PCint(); +//} int main(void) @@ -118,6 +166,7 @@ int main(void) cpu_init(); led_init(); USB_Init(); + TWI_Init(TWI_BIT_PRESCALE_1, TWI_BITLENGTH_FROM_FREQ(1, 200000)); sei(); for(;;) { -- cgit v1.2.3