STM32F407VGT6 CAN 无法使用

STM32系列
pyboard相关
回复
skylin008
帖子: 21
注册时间: 2020年 7月 21日 20:26

STM32F407VGT6 CAN 无法使用

#1

帖子 skylin008 »

各位大佬好!
       自己编译了一个STM32F407VGT6 的板子,在mpconfigboard.h 中设定了以下参数:
       

代码: 全选

#define MICROPY_HW_ENABLE_CAN       (1)


// CAN1 busses
#define MICROPY_HW_CAN1_TX (pin_D1) // PB9,PD1,PA12
#define MICROPY_HW_CAN1_RX (pin_D0) // PB8,PD0,PA11

// CAN2 busses
#define MICROPY_HW_CAN2_TX (pin_B13) // PB9,PD1,PA12,PB13
#define MICROPY_HW_CAN2_RX (pin_B12) // PB8,PD0,PA11,PB12
在测试时,2个端口自环都正常,自环代码如下:

代码: 全选

from pyb import CAN
can = CAN(2, CAN.LOOPBACK)
can.setfilter(0, CAN.LIST16, 0, (123, 124, 125, 126))  # set a filter to receive messages with id=123, 124, 125 and 126
while True:
    can.send('message!', 123)   # send a message with id 123
    l = can.recv(0)                 # receive message on FIFO 0
    print(l)
但在发送测试时,发完4个包后,就提示 OSError:16 ,测试代码如下,请问各位大佬是否有思路呢,谢谢!CAN 芯片为 CA-IS3050U.

代码: 全选

from machine import Pin
import uasyncio as asyncio


from pyb import CAN

can1 = CAN(2, CAN.NORMAL,prescaler=2, sjw=1, bs1=14, bs2=6 )

buf = bytearray(1)
buf[0] = 0

msg_id = 123

def printmsg(msg):
    buf[0] += 1
    print('msg: {} count: {}'.format(msg,buf[0]))
    can1.send((msg), msg_id)   



async def main():
    #pin = Pin(Pin.cpu.C4, Pin.IN, Pin.PULL_UP)
    #pb = Pushbutton(pin)
    #pb.press_func(printmsg, ('push', ))
    #pb.long_func(printmsg, ('long',))
    while True:
        await asyncio.sleep(1)       #keep the uasyncio loop alive
        printmsg('message')

try:
    asyncio.run(main())
except (KeyboardInterrupt, Exception) as e:
    #print('Exception {} {}\n'.format(type(e).__name__, e))
    pass
#finally:
#    ret = asyncio.new_event_loop()  # Clear retained uasyncio state

回复

  • 随机主题
    回复总数
    阅读次数
    最新文章