Can I use the can.recv(0) in the rxcallback function?

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
wwsheldons
Posts: 31
Joined: Wed Dec 02, 2015 1:47 pm

Re: Can I use the can.recv(0) in the rxcallback function?

Post by wwsheldons » Sat Jun 11, 2016 8:48 am

PappaPeppar wrote:Yes it should be possible to use it in all interrupt functions. The intention is that all callbacks will have the option to be soft. Next in queue is extint. If you find any bugs or comes up with any possible improvments while using this, please report them here or even better in the PR at github.

OK , thank you

tecdroid
Posts: 27
Joined: Thu Apr 08, 2021 6:22 am

Re: Can I use the can.recv(0) in the rxcallback function?

Post by tecdroid » Sat Dec 04, 2021 2:11 pm

Hi,
i also have a memory error

Code: Select all

from pyb import CAN
import gc

buf = bytearray(8)
fifo = [0,0,0,memoryview(buf)]

def cb1(bus, reason):
    print('rx callback')
    if reason == 0:
        val = bus.recv(0,fifo)
        print (val)
        #id, rtr, fmi, data
        #print('received {} [{}]'.format( id, data ))


def main():
    can = CAN(1, CAN.NORMAL, baudrate=125000)
    can.setfilter(0, CAN.MASK16, 0, (0x00, 0xf0, 0x30 ,0xf0))
    can.rxcallback(0, cb1)
    print(gc.mem_free())
    while True:
        pass
        #base.loop(can)

main()
results in (memory error after sending data):
>>> import cantest
100896
uncaught exception in CAN(1) rx interrupt handler
MemoryError:
my mp is compiled with softirq..

Post Reply