NRF905 with PIC16F887 help...

Hi

Im connecting a nrf905-module with a pic16f887. My problem is Im struggling with the code. I looked at the datasheet of the nrf905-module and still cant figure out how their protocol works.

Does anyone have code for transmitting and or receiving with a nrf905-module that will work on a pic16f887?

Or anyone that can just explain step by step how I must proceed?

Here is 2 parts of code, one for transmitting with the nrf905 and one for receiving data with nrf905. This is the code I’ve got so far. I don’t know how to clock data into the SPI and clock data out of the SPI. So I cannot set registers like TX_PAYLOAD and TX_ADDRESS. For coding sakes I’ve declared all these registers, the SPI registers, as variables and whenever I want to use these registers I use the variables. Obviously this will never work.

I will appreciate it if anyone can help me to complete the code or just tell me how to do it, PLEASE?!?!

CODE REMOVED

You really need to sit down with the datasheet for the PIC16F887 and read the section on SPI in Chapter 13 (MSSP) so you know what’s going on. Disconnect your nRF905 from the PIC and then short SDI and SDO together (known in actual SPI lingo as MISO and MOSI, respectively). When you can send bytes over the SDO line and then read the exact same bytes on the SDI line, then you are on your way. You will still have to make sure you have a chip select line working to complete the interface.

All of the necessary timing diagrams for the SPI interface with respect to the nRF905 can be found in the nRF905 datasheet in Sect. 9.3 (“SPI Timing”). In particular, note the timings for the CSN line.

This is my code so far. Can anyone help me with it? It’s not working and i don’t know why…

PLEASE can anyone point out to me where the error is.

CODE REMOVED

	movlw	RXDATA
	movwf	PORTD

This puts the address of RXDATA on PORTD, not the value. You aren’t going to be able to see it, anyway, because PORTD gets overwritten about 4 microseconds later, at the top of MAIN.

	movlw	b'00000011'
	movwf	SSPBUF			;Config address 3 (RX payload)
	movlw	b'00000001'		;One byte RX payload
	movwf	SSPBUF
	movlw	b'00000001'		;One byte TX payload
	movwf	SSPBUF

You have to wait for each individual transfer to complete before starting the next, they aren’t instantaneous!

Okay I’ve added a delay loop after each move. But it’s is still not working… The PORTD is just to blink a LED to make sure that the pic is working. Don’t want to use it for something specific.

HELP PLEASE?!?!?

	movlw	b'00000011'
	movwf	SSPBUF			;Config address 3 (RX payload)
	call		delay_loop

	movlw	b'00000001'		;One byte RX payload
	movwf	SSPBUF
	call		delay_loop

	movlw	b'00000001'		;One byte TX payload
	movwf	SSPBUF
	call		delay_loop

You need to poll the BF bit in the SSPSTAT register to determine when the SPI tranaction is complete. If that bit never gets set, you likely don’t have the SPI module set up properly. Example 13-1 on p. 184 of the datasheet shows this as the first two lines of assembly code.

Okay, i’ve made new code. This is suppose to work but it doesn’t. I can’t see where i’m going wrong. I output the received data to LED’s on PORTD and the LEDs flash but it sin’t the data that i send, all the LED’s flash and then all goes off. I’m sending 10101010 and then call a delay and then send 01010101 and then call the delay again. Sometimes the LED’s just stays of and sometimes the LEDs just stays on, after it blinked for a random amount of time.

PLEASE can anyone help me with this problem?!?! I’ve done everything that i could.

CODE REMOVED

You now have a lot of code like movf b’01010101’,w that should be movlw instead. What that does as written is put whatever garbage happens to be in address 0x55 into W, not the value 0x55.

Also, there are several places like this:

   	bsf		PORTA,PWRUP	;Power up nfr905
   	bsf      	PORTA,CSN   		;(CSN=1)
   	bcf      	PORTA,TRX_CE   	;(TRX_CE=0)

where you do successive bit operations to different bits on the same port. That does not work reliably unless you put a nop between each pair of instructions. (Look up “read-modify-write problem” for the gory details on why this is necessary, if you want.)

Now i’ve changed some of the movf to movlw where I think it was necessary. And added nop just to make sure. But the LEDs are still random. It doesn’t lit up in the pattern 01010101 then 10101010. Any other ideas to where the problem is?

Code Removed

I see no obvious errors in your code now; the only thing that even looks suspicious is the turning off of TX_EN and PWRUP after each transmission, which might be losing your register setup, or might require a longer delay for the module to power up again.

I’m afraid there’s not much more I can do to help, since I have no personal experience with this module.

As a first step, have you verified that 1) you can read the registers of the nRF905 when you power it up (and they’re correct), and 2) you can write to the registers of the nRF905 and then read them to verify that you sent the right numbers? If not, you’re not going to get too far. You should take the code one step at a time instead of trying to test it all at once. It’s far easier to diagnose problems that way.