From 619671ad7376cdc1536e72bd0d1948e8d3747e7e Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Thu, 13 Sep 2012 13:15:05 +0200 Subject: [PATCH] fix write function --- spi2Csr/tools/uart2Spi.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/spi2Csr/tools/uart2Spi.py b/spi2Csr/tools/uart2Spi.py index 8a60988e..aa0d961d 100644 --- a/spi2Csr/tools/uart2Spi.py +++ b/spi2Csr/tools/uart2Spi.py @@ -1,9 +1,10 @@ import string import time import serial +from struct import * -def write_ascii(uart, data): - uart.write(bytes("%c" % data, encoding="ascii")) +def write_b(uart, data): + uart.write(pack('B',data)) class Uart2Spi: def __init__(self, port, baudrate): @@ -13,20 +14,20 @@ class Uart2Spi: def read(self, addr): while True: - write_ascii(self.uart, 0x02) - write_ascii(self.uart, (addr>>8)&0xFF) - write_ascii(self.uart, (addr&0xFF)) - write_ascii(self.uart, 0x00) + write_b(self.uart, 0x02) + write_b(self.uart, (addr>>8)&0xFF) + write_b(self.uart, (addr&0xFF)) + write_b(self.uart, 0x00) read = self.uart.read() if len(read) == 1: break return read[0] def write(self, addr, data): - write_ascii(self.uart, 0x01) - write_ascii(self.uart, (addr>>8)&0xFF) - write_ascii(self.uart, (addr&0xFF)) - write_ascii(self.uart, data) + write_b(self.uart, 0x01) + write_b(self.uart, (addr>>8)&0xFF) + write_b(self.uart, (addr&0xFF)) + write_b(self.uart, data) def main(): csr = Uart2Spi(1,115200) -- 2.30.2