Я пытаюсь отправить сообщение «тест» из модуля, но сейчас я просто пытаюсь записать значение 0b11 в регистр SETUP_AW (
Код: Выделить всё
const(0x03)
Как я могу успешно записывать и читать значения из регистров и в конечном итоге отправлять сообщение?
Я пробовал запустить nrf24l01test.py и nrf24l01.py (с добавленными строками elif usys.platform == "rp2": cfg = {"spi": 0, "miso": 4, "mosi": 7, "sck": 6, "csn": 14 , "ce": 17), но это всегда выводит:
Код: Выделить всё
Traceback (most recent call last):
File "", line 154, in
File "", line 40, in master
File "nrf24l01.py", line 79, in __init__
OSError: nRF24L01+ Hardware not responding
Код MicroPython:< /strong>
Код: Выделить всё
from machine import SPI, Pin
from micropython import const
import time
spi = SPI(id=0, baudrate=500000, polarity=0, phase=0, sck=Pin(6), mosi=Pin(7), miso=Pin(4))
CE_PIN = Pin(17, Pin.OUT)
CSN_PIN = Pin(14, Pin.OUT)
CE_PIN.value(0) # Disable CE (standby mode for the NRF24L01)
CSN_PIN.value(1) # Deselect the NRF24L01
R_REGISTER = 0x00 # Read register command
CONFIG_REG = const(0x00) # Address of the CONFIG register
SETUP_AW = const(0x03) # Setup register
STATUS_REG = const(0x07) # Status register
buffer = bytearray(1)
def read_register(register):
CSN_PIN.value(0) # Select NRF24L01
spi.write(bytearray([0x00 | register])) # Send read command
spi.readinto(buffer, 1) # Read response into buffer
CSN_PIN.value(1) # Deselect NRF24L01
return buffer[0]
def write_register(register, value):
CSN_PIN.value(0) # Select NRF24L01
spi.write(bytearray([0x20 | register, value])) # Send write command and value
CSN_PIN.value(1) # Deselect NRF24L01
time.sleep(0.01) # Short delay for write to settle
write_register(CONFIG_REG, 0b00001111)
write_register(SETUP_AW, 0b11)
status = read_register(0x07)
print(f"STATUS register after write: 0x{status:02X}")
setup_aw_value = read_register(SETUP_AW)
print(f"Written the value 0x{0b11:02X} ({int(0b11)}) to reg {SETUP_AW}")
print(f"Read the value 0x{setup_aw_value:02X} ({int(setup_aw_value)}) from reg {SETUP_AW}")
Код: Выделить всё
STATUS register after write: 0x01
Written the value 0x03 (3) to reg 3
Read the value 0x01 (1) from reg 3
Значок NRF24L01
Raspberry Pi Pico GPIO
Физический контакт Raspberry Pi Pico
CE
17
22
CSN
14
19
SCK< /td>
6
9
MOSI
7
10
MISO
4
6
Принципиальная схема:
(Конденсатор 10 мкФ)
[img]https: //i.sstatic.net/xF76qT7i.png[/img]
Любая помощь приветствуется!
Подробнее здесь: https://stackoverflow.com/questions/791 ... icropython