bbcmicrobit / micropython

Port of MicroPython for the BBC micro:bit
https://microbit-micropython.readthedocs.io
Other
603 stars 284 forks source link

spi modes aren't as described in the documetation #651

Closed rhubarbdog closed 5 years ago

rhubarbdog commented 5 years ago

I have this microbit program

from microbit import *

baud = 9600

pin16.write_digital(0)
spi.init(baudrate = baud, bits = 8, mode = 0)

def recv_message(nbytes = 128):
    pin16.write_digital(1)
    sleep(1)
    text = spi.read(nbytes)
    pin16.write_digital(0)

    return text

while True:
    if button_a.is_pressed():
        text = recv_message(7)
        print(text)
        display.scroll(str(text))

and this pyboard program implmenting a slave

import pyb

spi = pyb.SPI(2, pyb.SPI.SLAVE, polarity = 1, bits = 8)

def slave_select(line):
    pyb.LED(4).on()
    spi.send('Cabbage')
    pyb.delay(500)
    pyb.LED(4).off()

pyb.ExtInt(pyb.Pin('Y5'), pyb.ExtInt.IRQ_RISING, pyb.Pin.PULL_DOWN,\
           slave_select)

while True:
    pyb.delay(1000)

and they work when i press button a in the microbit the pyboard transmits 'Cabbage' back to the microbit.

microbit spi mode is 0. the documents state this is polarity 0, phase 0 . To get the message 'Cabbage' correctly tranmitted the pyboard has to be in polarity 1,

rhubarbdog commented 5 years ago

ignore this i have resolved the issue, the code on my hard drive and pyboard had become out of sync