spi communication works!!eleven!

master
Dario Ernst 15 years ago
parent 8ac2673ac9
commit d8e0702729

@ -23,6 +23,7 @@ respectively.
#include <string.h>
#include <usb.h> /* this is libusb */
#include "opendevice.h" /* common code moved to separate module */
#include <arpa/inet.h> //for htons()
#include "../firmware/masterchip/usbdrv/usbconfig.h" /* device's VID/PID and names */
@ -101,6 +102,9 @@ int cnt, vid, pid;
opcode = atoi(argv[2]);
addr = atoi(argv[3]);
value = atoi(argv[4]);
// x86 is little-endian, avr is big-endian
value = htons(value);
cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, opcode, addr, value, buffer, sizeof(buffer), 5000);
if(cnt < 0){

@ -27,13 +27,13 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) {
usbMsgPtr = dataBuffer;
return 4;
} else {
uint8_t opcode = (uint8_t) rq->bRequest;
uint8_t addr = (uint8_t) rq->wValue.bytes[0];
uint8_t valH = (uint8_t) rq->wIndex.bytes[0];
uint8_t valL = (uint8_t) rq->wIndex.bytes[1];
uint8_t opcode = rq->bRequest;
uint8_t addr = rq->wValue.bytes[0];
uint8_t valH = rq->wIndex.bytes[0];
uint8_t valL = rq->wIndex.bytes[1];
uint16_t send = (valH << 8) | valL;
uint16_t recv = spi_master_transceive(opcode, addr, send);
recv = spi_master_transceive(opcode, addr, send);
dataBuffer[0] = (recv & 0xff00) >> 8;
dataBuffer[1] = (recv & 0xff);

@ -131,7 +131,7 @@ void spi_sla_handle_packet(){
// are sent.
opcode = readbuf[0];
addr = readbuf[1];
data = (readbuf[2]<<8)&0xff | readbuf[3];
data = (readbuf[2]<<8) | readbuf[3];
newdata = spi_proto_slaveaction(opcode, addr, data);
writebuf[1]=addr;
writebuf[2]=(newdata>>8)&0xff;

@ -16,7 +16,7 @@ uint16_t spi_master_transceive(uint8_t opcode, uint8_t addr, uint16_t value)
spi_mst_start_packet();
spi_mst_write_read(5,mst_buf);
spi_mst_end_packet();
} while(mst_buf[1] =! opcode || mst_buf[2] != addr); // wait for echoed opcode
} while(mst_buf[1] != opcode || mst_buf[2] != addr); // wait for echoed opcode
//TODO: validate opcode and addr
// bytes from slave are received shifted right by one

@ -1,8 +1,8 @@
#include "main.h"
#include "spi.h"
uint16_t foo = 0xfefe;
uint8_t bar = 0xee;
uint16_t foo;
uint8_t bar;
void baz() {

Loading…
Cancel
Save