Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add contrib script for 93c46 EEPROM #96

Merged
merged 1 commit into from
May 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions contrib/pyHydra_93c46/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Script to communicate with Hydrabus to 93c46 3-wire EEPROM.

The script uses the pyHydrabus library.
This script requires Python 3.2+

Dependencies:
pip3 install serial

Author: Sylvain Pelissier <[email protected]>

License: GPLv3 (https://choosealicense.com/licenses/gpl-3.0/)

(if license conflicts with hydrafw license, hydrafw license prevails)
73 changes: 73 additions & 0 deletions contrib/pyHydra_93c46/hydra_93c46.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/usr/bin/env python3
#
# Script to communicate to 94c46 3-wire EEPROM with Hydrabus.
#
# Author: Sylvain Pelissier <[email protected]>
# License: GPLv3 (https://choosealicense.com/licenses/gpl-3.0/)
#
import pyHydrabus

from binascii import hexlify

def write_enable():
# Write enable is 10011XXXX
cs.value=1
sm.sda = 1
sm.clock()
sm.sda = 0
sm.clocks(2)
sm.sda = 1
sm.clocks(8)
cs.value=0

def write_disable():
# Write disable is 10000XXXXX
cs.value=1
sm.sda = 1
sm.clock()
sm.sda = 0
sm.clocks(10)
cs.value=0

def read(address, num):
address = address & 0x3f
cs.value=1
sm.write(bytes([0x01, 0x80 | address]))
data = sm.read(num)
cs.value=0

return data

def write(address, data):

if len(data) % 2 == 1:
print("Data length must be even")
exit(2)

for i in range(0, len(data) , 2):
cs.value=1
sm.write(bytes([0x01, 0x40 | address+i//2]) + data[i:i+2])
cs.value=0

if __name__ == '__main__':
sm=pyHydrabus.RawWire('/dev/ttyACM0')
sm.gpio_mode = 1
sm.set_speed(50000)
sm.wires = 3

# CS pin configuration with auxiliary pin PC4
cs = sm.AUX[0]
cs.direction=0
cs.value=0

# Read memory cotent
print(hexlify(read(0, 128)))

# Write 4 bytes of data
write_enable()
data = b"\xa5\xa6\x45\x46"
write(0,data)
write_disable()

# Read memory cotent
print(hexlify(read(0, 128)))
2 changes: 1 addition & 1 deletion contrib/pyHydrabus/pyHydrabus/auxpin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class AUXPin():
:example:

>>> import pyHydrabus
>>> i=pyHydrabus.I2C('/dev/hydrabus')
>>> i=pyHydrabus.RawWire('/dev/hydrabus')
>>> # Set AUX pin 0 (PC4) to output
>>> i.AUX[0].direction = 0
>>> # Set AUX pin to logical 1
Expand Down
13 changes: 10 additions & 3 deletions contrib/pyHydrabus/pyHydrabus/rawwire.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@ class RawWire(Protocol):

:example:

TODO
>>> import pyHydrabus
>>> i=pyHydrabus.I2C('/dev/hydrabus')
>>> # Set SDA to high
>>> sm.sda = 1
>>> # Send two clock ticks
>>> sm.clocks(2)
>>> # Read two bytes
>>> data = sm.read(2)

"""

Expand Down Expand Up @@ -254,7 +261,7 @@ def wires(self, value):
@property
def gpio_mode(self):
"""
Raw-Wire GPIO mode (1=Push-Pull, 2=Open Drain)
Raw-Wire GPIO mode (0=Push-Pull, 1=Open Drain)
"""
return (self._config & 0b1000) >> 3

Expand All @@ -269,5 +276,5 @@ def gpio_mode(self, value):
self._configure_port()
return True
else:
self._logger.error("Incorrect value. Must be 1 or 2")
self._logger.error("Incorrect value. Must be 0 or 1")