Initialize CAN, I2C, and RS485 communication modules, then in a loop, read and process data based on interrupts and data status. Generate random data and send it via CAN and RS485, while scanning and checking the status of I2C devices.
from m5stack import *
from m5ui import *
from uiflow import *
import module
import time
setScreenColor(0x3a3a3a)
rand = None
temp_data = None
com = module.get(module.COMMU)
import random
com.commu_can_init(3, 15)
i2c = com.commu_i2c_init(21, 22, 0x44, 100000)
rs485 = com.commu_uart_init(2, 17, 16, 115200, 8, None, 1)
print((str('I2C Device:') + str((i2c.scan()))))
while True:
if com.commu_can_interrupt_occur():
print((str('CAN Message:') + str((com.commu_can_read_message(1)))))
print((str('CAN ID:') + str((com.commu_can_id))))
if i2c.available():
print('TRUE')
print((str('I2C Device:') + str((i2c.scan()))))
else:
print('FALSE')
if rs485.any():
print((str('RS485 Data:') + str((rs485.read()).decode())))
rand = random.randint(10000000, 16777215)
wait(1)
temp_data = [(rand & 0xff0000) >> 16, (rand & 0x00ff00) >> 8, rand & 0xff]
com.commu_can_send_message(0x100, temp_data)
print((str('temp data:') + str(temp_data)))
wait(1)
rs485.write(str(rand))
print((str('rand data:') + str(rand)))
wait_ms(2)
com.commu_can_available_message()
com.commu_can_clear_interrupts()
com.commu_can_config_rate(15)
com.commu_can_debug(True)
com.commu_can_init(3, 15)
com.commu_can_interrupt_occur()
com.commu_can_read_message(1)
com.commu_can_id
com.commu_can_reset()
com.commu_can_send_message(0x100, [0, 0, 0])
com.commu_can_set_mode(0x00)
i2c.available()
[][0]
com.commu_i2c_init(21, 22, 0x50, 100000)
i2c.read_data(0, i2c_bus.UINT8LE)
i2c.read_mem_data(0, 0, i2c_bus.UINT8LE)
i2c.read_reg(0x00, 0)
i2c.read_u8(0x00)
i2c.read_u16(0x00, byteorder="big")
i2c.scan()
i2c.write_u16(0x00, 0x0000, byteorder="big")
i2c.write_u8(0x00, 0x00)
i2c.write_data(0, i2c_bus.UINT8LE)
i2c.write_mem_data(0, 0, i2c_bus.UINT8LE)
i2c.write_mem_list(0, [0, 0, 0])
uart.any()
com.commu_uart_init(1, 1, 3, 9600, 8, None, 1)
uart.read()
uart.readline()
uart.read(0)
uart.write('')
uart.write(''+"\r\n")
uart.write(bytes([0, 0, 0]))