diff --git a/cmdline/read-temp.c b/cmdline/read-temp.c index 9567b7c..8d9a183 100644 --- a/cmdline/read-temp.c +++ b/cmdline/read-temp.c @@ -23,6 +23,7 @@ respectively. #include #include /* this is libusb */ #include "opendevice.h" /* common code moved to separate module */ +#include //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){ diff --git a/firmware/masterchip/usb.c b/firmware/masterchip/usb.c index 12f6682..f1bbfc5 100644 --- a/firmware/masterchip/usb.c +++ b/firmware/masterchip/usb.c @@ -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); diff --git a/firmware/shared/spi.c b/firmware/shared/spi.c index 83902fc..f0a14d8 100644 --- a/firmware/shared/spi.c +++ b/firmware/shared/spi.c @@ -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; diff --git a/firmware/shared/spi_proto.c b/firmware/shared/spi_proto.c index 6259a6b..7d3fee2 100644 --- a/firmware/shared/spi_proto.c +++ b/firmware/shared/spi_proto.c @@ -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 diff --git a/firmware/slavechip/main.c b/firmware/slavechip/main.c index debf805..e37b161 100644 --- a/firmware/slavechip/main.c +++ b/firmware/slavechip/main.c @@ -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() {