STM32F411CEU6 BlackPill @nspsck build SPI weird behaviour #12772
-
I am trying to get ulora to work using the @nspsck build for the STM32F411. I had one board sending a test message for hours then it stopped. Re-booting shows Doing a mass_erase and putting the firmware/software back on it still would not work. I have found that I if I do the SPI stuff (both pyb.SPI and machine.SoftSPI) before I ulora.py see (https://github.com/martynwheeler/u-lora/blob/main/ulora.py) class LoRa(object):
def __init__(): seems to be the problem. BTW, another board running the same ulora.py and a receive Also, I am assuming that I can put a SoftSPI on pins that were mapped in the build for I can only conclude that when the board failed that something got broken that now does Why in a class does spi.write('hello') become self._spi_write('hello')?? I have some more BlackPills on order but was hoping that I could understand what |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 38 replies
-
Ugh, it is really hard to tell you what is going on without seeing what exactly you were doing/trying to do.
The
To my knowledge, there is no "private" function like Java in Python. The "_" at the beginning is just a convention to prevent the
Sorry, I do not fully understand what you are trying to do here, but I hope I could help you with the following: Based on the included modules by the class SPIConfig():
# spi pin defs for various boards (channel, sck, mosi, miso)
stm32_2 = (2)
stm32_3 = (3)
rp2_0 = (0, 6, 7, 4)
rp2_1 = (1, 10, 11, 8)
esp8286_1 = (1, 14, 13, 12)
esp32_1 = (1, 14, 13, 12)
esp32_2 = (2, 18, 23, 19) Because the SPI pins on stm32 ports are predefined, you can not change the on the fly. So you need to do the following to line 127. if len(self._spi_channel) < 4: # That is: you only have one value in the list.
self.spi = SPI(self._spi_channel[0], baudrate=3000000) # You can only get 3MHz on this board.
else:
self.spi = SPI(self._spi_channel[0], 5000000,
sck=Pin(self._spi_channel[1]), mosi=Pin(self._spi_channel[2]), miso=Pin(self._spi_channel[3])) Then you should be able to use the module as in the README.md. Sadly, neither did I own a lora device nor I ever had experience with those, this is as far as I could help. The preconfigured SPI pins should be correct, since these are configured according to the official reference manual. Ugh, and I am going to sleep... So if you have quetions to my explaination.. I won't be able to respond for the next few (6-12) hours. |
Beta Was this translation helpful? Give feedback.
-
Thank you for your answer re _spi_write If I look further down ulora.py I do see that method, so that issue is sorted. I had put
If you do not use SPI2 then you could use those pins for a SoftSPI, correct? A few minor changes to your suggestion as a list with one item is a singleton list and is of type int.. So you can not find it's length. # setup the hardware SPI
if self._spi_channel == SPIConfig.stm32_2 or self._spi_channel == SPIConfig.stm32_3:
self.spi = SPI(self._spi_channel, baudrate=3000000) # you can only get 3MHz on the BlackPill
else:
self.spi = SPI(self._spi_channel[0], 5000000,
sck=Pin(self._spi_channel[1]), mosi=Pin(self._spi_channel[2]), miso=Pin(self._spi_channel[3])) Really appreciate your very helpful answer. However, the board with the above changes worked once or twice and then stop working ... throws-up "LoRa initialization failed". Some testing ... if I put this in main.py: from time import sleep
from machine import Pin, SPI
print ('wait 2 seconds for a CTRL-C')
sleep(2)
try:
spi = SPI(2, baudrate=3000000)
spi.write(b'hello')
except:
print ('write failed')
print ('finished') No problems. However, if I do this in ulora.py # setup the hardware SPI
if self._spi_channel == SPIConfig.stm32_2 or self._spi_channel == SPIConfig.stm32_3:
self.spi = SPI(self._spi_channel, baudrate=3000000) # you can only get 3MHz on the BlackPill
else:
self.spi = SPI(self._spi_channel[0], 5000000,
sck=Pin(self._spi_channel[1]), mosi=Pin(self._spi_channel[2]), miso=Pin(self._spi_channel[3]))
print (f'self.spi = {self.spi}')
try:
self._spi_write(b'hello')
except:
print ('spi write failed') I get some 'spi write failed' and then "LoRa initialization failed". Maybe, my try/except test is not valid and SPI comms with the RFM96W is what is really failing. |
Beta Was this translation helpful? Give feedback.
-
My original server.py and Martyn's ulora.py works with a sender using ulora_rkompass.py |
Beta Was this translation helpful? Give feedback.
Ugh, it is really hard to tell you what is going on without seeing what exactly you were doing/trying to do.
The
spi.write()
is provided by themachine
module and it provides only a basic communication protocol. The_spi_write()
is provided by theulora
module and it includes some setups for the lora device and usesspi.write()
to communicate with the lora device. These are two different functions with different purpose, hence one never became another.To my knowledge, there is no "private" function like Java in Python. The "_" at …