Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # * Copyright (c) 2015 seeed technology inc.
- # * Author : Jiankai Li
- # * Create Time: Nov 2015
- # * Change Log : Seth Dec. 2019 w/ help from #beagle at Freenode
- # * and Prabakar's book called, "BealgeBone by Example."
- # FileName : MotorBridge.py
- # by Jiankai.li
- from smbus2 import SMBus
- import time
- import pathlib
- # reset pin is P9.23, i.e. gpio1.17
- reset_pin = pathlib.Path('/sys/class/gpio/gpio49/direction')
- reset_pin.write_text('low')
- bus = SMBus('/dev/i2c-2')
- ReadMode = 0
- WriteMode = 1
- DeAddr = 0X4B
- ConfigValid = 0x3a6fb67c
- DelayTime = 0.005
- # TB_WORKMODE
- TB_SHORT_BREAK = 0
- TB_CW = 1
- TB_CCW = 2
- TB_STOP = 3
- TB_WORKMODE_NUM = 4
- # TB_PORTMODE
- TB_DCM = 0
- TB_SPM = 1
- TB_PORTMODE_NUM = 2
- # SVM_PORT
- SVM1 = 0
- SVM2 = 1
- SVM3 = 2
- SVM4 = 3
- SVM5 = 4
- SVM6 = 5
- SVM_PORT_NUM = 6
- # SVM_STATE
- SVM_DISABLE = 0
- SVM_ENABLE = 1
- SVM_STATE_NUM = 2
- # IO_MODE
- IO_IN = 0
- IO_OUT = 1
- IO_MODE_NUM = 2
- # IO_PUPD
- IO_PU = 0
- IO_PD = 1
- IO_NP = 2
- IO_PUPD_NUM = 3
- # IO_PPOD
- IO_PP = 0
- IO_OD = 1
- IO_PPOD_NUM = 2
- # IO_STATE
- IO_LOW = 0
- IO_HIGH = 1
- IO_STATE_NUM = 2
- # IO_PORT
- IO1 = 0
- IO2 = 1
- IO3 = 2
- IO4 = 3
- IO5 = 4
- IO6 = 5
- IONUM = 6
- # PARAM_REG
- CONFIG_VALID = 0
- CONFIG_TB_PWM_FREQ = CONFIG_VALID + 4
- I2C_ADDRESS = CONFIG_TB_PWM_FREQ + 4
- TB_1A_MODE = I2C_ADDRESS + 1
- TB_1A_DIR = TB_1A_MODE + 1
- TB_1A_DUTY = TB_1A_DIR + 1
- TB_1A_SPM_SPEED = TB_1A_DUTY + 2
- TB_1A_SPM_STEP = TB_1A_SPM_SPEED + 4
- TB_1B_MODE = TB_1A_SPM_STEP + 4
- TB_1B_DIR = TB_1B_MODE + 1
- TB_1B_DUTY = TB_1B_DIR + 1
- TB_1B_SPM_SPEED = TB_1B_DUTY + 2
- TB_1B_SPM_STEP = TB_1B_SPM_SPEED + 4
- TB_2A_MODE = TB_1B_SPM_STEP + 4
- TB_2A_DIR = TB_2A_MODE + 1
- TB_2A_DUTY = TB_2A_DIR + 1
- TB_2A_SPM_SPEED = TB_2A_DUTY + 2
- TB_2A_SPM_STEP = TB_2A_SPM_SPEED + 4
- TB_2B_MODE = TB_2A_SPM_STEP + 4
- TB_2B_DIR = TB_2B_MODE + 1
- TB_2B_DUTY = TB_2B_DIR + 1
- TB_2B_SPM_SPEED = TB_2B_DUTY + 2
- TB_2B_SPM_STEP = TB_2B_SPM_SPEED + 4
- SVM1_STATE = TB_2B_SPM_STEP + 4
- SVM1_FREQ = SVM1_STATE + 1
- SVM1_ANGLE = SVM1_FREQ + 2
- SVM2_STATE = SVM1_ANGLE + 2
- SVM2_FREQ = SVM2_STATE + 1
- SVM2_ANGLE = SVM2_FREQ + 2
- SVM3_STATE = SVM2_ANGLE + 2
- SVM3_FREQ = SVM3_STATE + 1
- SVM3_ANGLE = SVM3_FREQ + 2
- SVM4_STATE = SVM3_ANGLE + 2
- SVM4_FREQ = SVM4_STATE + 1
- SVM4_ANGLE = SVM4_FREQ + 2
- SVM5_STATE = SVM4_ANGLE + 2
- SVM5_FREQ = SVM5_STATE + 1
- SVM5_ANGLE = SVM5_FREQ + 2
- SVM6_STATE = SVM5_ANGLE + 2
- SVM6_FREQ = SVM6_STATE + 1
- SVM6_ANGLE = SVM6_FREQ + 2
- IO1_STATE = SVM6_ANGLE + 2
- IO1_MODE = IO1_STATE + 1
- IO1_PUPD = IO1_MODE + 1
- IO1_PPOD = IO1_PUPD + 1
- IO2_STATE = IO1_PPOD + 1
- IO2_MODE = IO2_STATE + 1
- IO2_PUPD = IO2_MODE + 1
- IO2_PPOD = IO2_PUPD + 1
- IO3_STATE = IO2_PPOD + 1
- IO3_MODE = IO3_STATE + 1
- IO3_PUPD = IO3_MODE + 1
- IO3_PPOD = IO3_PUPD + 1
- IO4_STATE = IO3_PPOD + 1
- IO4_MODE = IO4_STATE + 1
- IO4_PUPD = IO4_MODE + 1
- IO4_PPOD = IO4_PUPD + 1
- IO5_STATE = IO4_PPOD + 1
- IO5_MODE = IO5_STATE + 1
- IO5_PUPD = IO5_MODE + 1
- IO5_PPOD = IO5_PUPD + 1
- IO6_STATE = IO5_PPOD + 1
- IO6_MODE = IO6_STATE + 1
- IO6_PUPD = IO6_MODE + 1
- IO6_PPOD = IO6_PUPD + 1
- PARAM_REG_NUM = IO6_PPOD + 1
- def WriteByte(Reg, Value):
- data = [0 for i in range(2)]
- data[0] = Reg
- data[1] = Value
- bus.write_i2c_block_data(0x4b, 1, data)
- def WriteHalfWord(Reg, Value):
- data = [0 for i in range(3)]
- data[0] = Reg
- data[1] = Value & 0xff
- data[2] = (Value>>8) & 0xff
- bus.write_i2c_block_data(0x4b, 1, data)
- def WriteOneWord(Reg, Value):
- data = [0 for i in range(5)]
- data[0] = Reg
- data[1] = Value & 0xff
- data[2] = (Value>>8) & 0xff
- data[3] = (Value>>16) & 0xff
- data[4] = (Value>>24) & 0xff
- bus.write_i2c_block_data(0x4b, 1, data)
- def SetDefault():
- WriteOneWord(CONFIG_VALID, 0x00000000)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement