I am trying to listen for bluetooth advertising packets in nRF52832 (pinetime watch to be exact).
What is the minimum required code to program radio in pure bare environment (i.e. in reset interrupt handler without SoftDevice)?
I have following code and it does not work: it always exits with timeout waiting for address. In timeout handler I see that radio is in state 3 "RADIO is in the RX state".
.thumb_func
_radio:
LDR R3, =(80*256*256*256 + 26*256*256 + 2*256 + 0)
_listen:
LDR R5, =RADIO_BASE
MOV R0, 0
STR R0, [R5, RADIO_POWER]
Sleep R0, 32
MOV R0, 1
STR R0, [R5, RADIO_POWER]
LDR R0, =(3) // Nrf_1Mbit=0, Ble_1Mbit=3, Ble_2Mbit=4
STR R0, [R5, RADIO_MODE]
LDR R0, =((0<<24) | (1<<20) | (0<<16) | (1<<8) | 8) // LFLEN=8 bit, S0LEN=1 bytes, S1LEN=0bit, S1INCL=1, preamble 8bit
STR R0, [R5, RADIO_PCNF0]
LDR R0, =((1<<25) | (0<<24) | (3<<16) | (0<<8) | 64) // MAXLEN=64 bytes, STATLEN=0, BALEN=3+1 bytes to transfer, LSBit first, WHITEN=0
STR R0, [R5, RADIO_PCNF1]
LDR R0, =((2<<8) | 1) // Fast rampup, 2=Transmit center frequency
STR R0, [R5, RADIO_MODECNF0]
LDR R0, =(150)
STR R0, [R5, RADIO_TIFS]
LDR R0, =(0x89BED600) // 0x8E89BED6
STR R0, [R5, RADIO_BASE0]
LDR R0, =(0x8E)
STR R0, [R5, RADIO_PREFIX0]
LDR R0, =((0x10000) | (1<<0)) // Use address 0 to recieve packets // workaround errata nrf52832 3.41 [143]
STR R0, [R5, RADIO_RXADDRESSES]
LDR R0, =(RAM_BASE + FLASH_PAGE_SIZE)
STR R0, [R5, RADIO_PACKETPTR]
ROR R3, 8
AND R0, R3, 0xFF
STR R0, [R5, RADIO_FREQUENCY] // Map 2400 .. 2500 MHz, use channel 66
MOV R0, 1
STR R0, [R5, RADIO_TASKS_RXEN]
LDR R4, =(8*1024*1024)
_ready:
SUBS R4, 1
BEQ _timeout
LDR R0, [R5, RADIO_EVENTS_READY]
CMP R0, 0
BEQ _ready
MOV R0, 1
STR R0, [R5, RADIO_TASKS_START]
LDR R4, =(16*1024*1024)
_addr:
SUBS R4, 1
BEQ _timeout
LDR R0, [R5, RADIO_EVENTS_ADDRESS]
CMP R0, 0
BEQ _addr
Do I miss something?
I.e. configure some frequency sources or set some GPIOs?
PS Hardware is ok: when I upload original firmware I can see watch advertises itself on both phones.
PPS. The addresses RADIO_* has been taken from nRF52832_PS_v1.4.pdf
Thank you.