Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : Now I know why I didn't bother with the nRF24L01...
Author | Message | ||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6783 |
SPI works great. I can read registers fine. I can't change them though, no matter whether CE is raised or not (it should be low to enable TX & RX functions). As I can't change the config register I can't take it in and out of Power Up mode. The module is mounted on one of the little breakout boards so it has its own regulator. My target Pico is a RP2040-Zero. This is as far as I've got. Please excuse all the little bits of testing rubbish that's cluttering the place up. :) 'nRF24L01 test Const nrf.cs = MM.Info(pinno GP0) Const nrf.mosi = MM.Info(pinno GP3) Const nrf.miso = MM.Info(pinno GP4) Const nrf.sck = MM.Info(pinno gp2) Const nrf.ce = MM.Info(pinno GP1) SetPin nrf.cs, dout Pin(nrf.cs)=1 'set nrf CSN high (SPI select) SetPin nrf.ce, dout Pin(nrf.ce)=1 'set nrf CE high. Enables TX/RX when low SetPin nrf.miso, nrf.mosi, nrf.sck, spi '========================== 'Test Routines nrf.init 'initialise the SPI (working) 'Print Bin$(nrf.status(),8) 'print the status register (working) 'Print Bin$(nrf.reg.r(0),8) 'print the contents of register number (working) 'nrf.writereg 1,&h00 'Print Bin$(nrf.reg.r(1),8) 'nrf.getregs(nrf.regs()) 'For i=0 To 24 'Print Hex$(i,2)" "Bin$(nrf.regs(i),8) 'Next Pin(nrf.ce) = 1 'the right way to do it is to read the reg, twiddle the bit then write it. 'only it doesn't work. 'a = nrf.reg.r(0) Print Bin$(nrf.reg.r(0),8) 'display reg 0 'b = nrf.bittwiddle(a, 1, 1) 'Print b nrf.writereg 0, 1 'just set reg 0 to 1 just as a test Print Bin$(nrf.reg.r(0),8) 'display reg 0 again '========================== Sub nrf.init SPI open 1000000, 1, 8 '1MHz, Mode 1, 8-bit SPI write 1, 0 'sets the SPI SCK high using a dummy write End Sub Function nrf.status() 'sends 8-bit NOP and returns status register Pin(nrf.cs) = 0 nrf.status = SPI(&hFF) Pin(nrf.cs) = 1 End Function Function nrf.reg.r(regnum) 'sends regnum and returns the contents of that register Local junk Pin(nrf.cs) = 0 junk = SPI(regnum) nrf.reg.r = SPI(&h00) Pin(nrf.cs) = 1 End Function Sub nrf.writereg(regnum%, byte%) 'not working Local junk Pin(nrf.cs) = 0 'junk = SPI(&h20) junk = SPI(regnum%+32) 'set bit 5 of the register address for write mode junk = SPI(byte%) Pin(nrf.cs) = 1 End Sub 'set or reset bit "place" in "num" - by cwit Function NRF.BITTWIDDLE(num,place,value) Local junk$,temp$,x$ x$=Str$(value) junk$=Bin$(num,8) For I=1 To 8 If I=(8-(place-1)) Then temp$=temp$+x$ Else temp$=temp$+Mid$(junk$,I,1) EndIf Next I NRF.BITTWIDDLE=Val("&b"+temp$) End Function It's a very interesting little chip. Low current drain but a reasonable range. Has no wifi connection so more or less immune to hacking. Each chip can have up to 6 "pipes" to other chips, making a small single-master network. All the packet work, CRC, ACK etc. is done on chip. It's also pretty cheap, even if it has been around for a while now. It's supported by A*****o libraries, of course, but I wouldn't stoop so low. :) ======================================= UPDATE: I think I've found the problem. In spite of what the SPI timingg diagram seems to suggest, it looks like it's actually a Mode 0 device, not Mode 1. I need to check further but I think writing to registers is working now. :) Edited 2024-07-02 17:58 by Mixtel90 Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 4223 |
Mick, Are you trying to control one of these JDY-40 modules. Volhout PicomiteVGA PETSCII ROBOTS |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6783 |
Nope, not this time. I've had JDY-40 working well, apart from straight modem replacement. I had a bit of trouble with that. The contact in, LED out system is very good! These are a different module, the nRF24L01. They are a sort of networking chip with an SPI interface. I'm now able to read and write the registers ok. Still sorting out little routines that are needed, then I need to sort out setting up one as a transmitter and one as a receiver to see if I can get them to work in simple mode. . Edited 2024-07-03 05:36 by Mixtel90 Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 4223 |
I think I read somewhere the JDY-40 uses the same chip. Must be wrong then. Volhout PicomiteVGA PETSCII ROBOTS |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6783 |
Nope, I don't think so. There's no actual control interface on the JDY-40, it's basically a modem with an 8-bit parallel port. You control it with AT commands. Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 4223 |
Hi mIck, So why look at the NRF24L01 ? Is it availability ? (I noticed out local shop is out of JDY-40's). Is it any benefit to look at the Arduino C libraries ? Some of them may be portable to basic. For a communication chip it may be hard to develop from datasheet, since you cannot test anything until you have 2 setups running. And 90% of the work is in the dynamic behaviour (re-connecting after a disconnect, how to handle poor signals). As far as I can see this lies partly in the driver, it is not completely handled by the chip itself. Volhout Edited 2024-07-03 17:14 by Volhout PicomiteVGA PETSCII ROBOTS |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6783 |
If I absolutely have to I'll rig up an arduino somehow to act as one half of the pair, but cwit did a lot of work getting these things to work on the Micromite some time ago. I have his stuff to work from as well as the info from the web. In actual fact the data sheet is pretty good and explains a lot of it quite well. Also, by default, the settings appear to be sensible for a simple 1-1 link. The chip has a couple of gotchas that aren't obvious at first. CEN is the SPI select pin. CE enables the RF section. To switch between TX and RX you change a bit in a register, it's not on a pin. Easy enough to sort out once you get into it. The SPI always returns the STATUS register when you send it a byte, so you just have to watch what's happening - you may not want that info. OTOH, if you want the status send it a NOP. It's quicker than requesting the contents of register &h07. :) You send data by writing the characters to a shift register. Then you send the appropriate command and they are sent automatically. You define the message length as either fixed or variable up to 39 characters (if I've understood it correctly). It's not like squirting text over a COM port. I'm looking at it for two reasons. I already have a pair that I never got round to playing with and they are remarkably cheap too. :) Not as easy to use as the JDY-40 but they are a more powerful system. Their closest competition is, I suppose, the smallest ESP modules, but they have no IO port and don't connect to wifi. For a small home automation system with one main control and up to six outstations they look good. Each outstation link is a pipe in its own right and can be configured individually, so some could be fixed length messages and some can be variable - all handled on the chip with CRC error checking, ACK and auto retry handling - something that the JDY-40 simply can't do. Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
Print this page |