[jallib/jallib] 1dd7c1: Added new JAL library for the nRF905

54 views
Skip to first unread message

Rob Jansen

unread,
Jul 26, 2020, 9:02:53 AM7/26/20
to jal...@googlegroups.com
Branch: refs/heads/master
Home: https://github.com/jallib/jallib
Commit: 1dd7c1bb5e824c27ec6928b1c4d4d98c192cde86
https://github.com/jallib/jallib/commit/1dd7c1bb5e824c27ec6928b1c4d4d98c192cde86
Author: Rob Jansen <12682653+R...@users.noreply.github.com>
Date: 2020-07-26 (Sun, 26 Jul 2020)

Changed paths:
M CHANGELOG
M TORELEASE
R include/external/nrf24l01/nrf24l01.jal
R include/external/virtual_wire/virtual_wire.jal
R include/external/virtual_wire/virtual_wire_receiver.jal
R include/external/virtual_wire/virtual_wire_transmitter.jal
A include/external/wireless/nrf24l01.jal
A include/external/wireless/nrf905.jal
A include/external/wireless/virtual_wire.jal
A include/external/wireless/virtual_wire_receiver.jal
A include/external/wireless/virtual_wire_transmitter.jal
A sample/16f1823_nrf905.jal
A sample/16f1825_nrf905.jal

Log Message:
-----------
Added new JAL library for the nRF905

Also moved all wireless libraries to a common wireless library on Github.


Gilles BARTHELEMY

unread,
Jul 26, 2020, 9:18:23 AM7/26/20
to jal...@googlegroups.com
Thank you Rob !!

--
You received this message because you are subscribed to the Google Groups "jallib" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jallib+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jallib/jallib/jallib/push/refs/heads/master/7db43a-1dd7c1%40github.com.

Rob CJ

unread,
Jul 26, 2020, 11:30:02 AM7/26/20
to jal...@googlegroups.com
Hi Gilles,

You're welcome.  

Let me know if you run into any issues using this library.

Kind regards,

Rob



Van: jal...@googlegroups.com <jal...@googlegroups.com> namens Gilles BARTHELEMY <bar...@gmail.com>
Verzonden: zondag 26 juli 2020 15:18
Aan: jal...@googlegroups.com <jal...@googlegroups.com>
Onderwerp: Re: [jallib] [jallib/jallib] 1dd7c1: Added new JAL library for the nRF905
 

bar...@gmail.com

unread,
Feb 8, 2021, 8:50:35 AM2/8/21
to jallib
Hello Rob

A bit late :-( but I never could make this library work for me.

Here is my code, which is a simple copy of your sample, whithout the use of interruptions.

-- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
-- %                                                                           %
-- %                    Test Module nRF905                                     %
-- %                                                                           %
-- % Langage JALV2                                                             %
-- % GBA 01/2021                                                               %
-- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

include 18f45k22                     -- target PICmicro
--
-- This program assumes that a 20 MHz resonator or crystal
-- is connected to pins OSC1 and OSC2.
pragma target clock 20_000_000      -- oscillator frequency
--
pragma target OSC      HSH                       -- crystal or resonator
pragma target PLLEN    DISABLED                  -- PLL off
pragma target WDT      DISABLED                  -- watchdog
pragma target XINST    DISABLED                  -- do not use extended instructionset
pragma target DEBUG    DISABLED                  -- no debugging
pragma target BROWNOUT DISABLED                  -- no brownout reset
pragma target FCMEN    DISABLED                  -- no clock monitoring
pragma target IESO     DISABLED                  -- no int/ext osc switching
pragma target LVP      ENABLED                  --  low voltage programming
pragma target MCLR     INTERNAL                  -- no external reset
--
-- The configuration bit settings above are only a selection, sufficient
-- for this program. Other programs may need more or different settings.
--
OSCCON_SCS = 0                      -- select primary oscillator
OSCTUNE_PLLEN = FALSE               -- no PLL

include delay
include print                          -- formatted output library

-- Active les résistances pull-up du port B
INTCON2_NRBPU = 0
-- Désactive les convertisseurs A/D
enable_digital_io()

-- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
-- % Traitement du port RS232
-- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
-- -- Définition des valeurs du port série
const USART_HW_Serial     = TRUE   -- TRUE = RS232, FALSE = SPI
const Serial_HW_Baudrate  = 9600

pin_c5_direction = output
pin_c6_direction = output
pin_c7_direction = input
include Serial_Hardware
Serial_HW_Init

pin_c5 = HIGH

-- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
-- % FIN Traitement du port RS232
-- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

enable_digital_io()
-- Take some time to stabilize.
_usec_delay(100_000)

-- For debugging purposes this constant can be defined.
const NRF905_DEBUG = TRUE

-- nRF905 pin definition.
alias nrf905_spi_sck is pin_C0 -- Pin 10 for 14 pin DIP
alias nrf905_spi_sck_direction is pin_C0_direction -- To SCK of nRF905
alias nrf905_spi_sdi is pin_C1 -- Pin 9 for 14 pin DIP.
alias nrf905_spi_sdi_direction is pin_C1_direction -- To MISO of nRF905
alias nrf905_spi_sdo is pin_C2 -- Pin 8 for 14 pin DIP.
alias nrf905_spi_sdo_direction is pin_C2_direction -- To MOSI of nRFF905
alias nrf905_csn_pin is pin_C3 -- Pin 7 for 14 pin DIP.
alias nrf905_csn_pin_direction is pin_C3_direction -- To csn of nRF905
alias nrf905_txen_pin is pin_A5 -- Pin 2 for 14 pin DIP.
alias nrf905_txen_pin_direction is pin_A5_direction -- To txen of nRF905
alias nrf905_trx_ce_pin is pin_A4 -- Pin 3 for 14 pin DIP.
alias nrf905_trx_ce_pin_direction is pin_A4_direction  -- To (tx_)ce of nRF905

-- We use software SPI. If not defined, hardware SPI is used.
const bit NRF905_SOFTWARE_SPI = TRUE

-- When using the power pin, define it here. If not used connect the power pin
-- of the module to VCC.
-- const NRF905_USE_PWR_PIN = TRUE
if defined(NRF905_USE_PWR_PIN) then
   alias nrf905_pwr_up_pin is pin_A1 -- Pin 12 for 14 pin DIP.
   alias nrf905_pwr_up_pin_direction is pin_A1_direction
end if

-- This program uses the interrupt way of receiving new data which gives the
-- main program more time before processing it. But since the main program does
-- not do very much this feature is not really needed here.
--const NRF905_USE_INTERRUPT = TRUE
if defined(NRF905_USE_INTERRUPT) then
   alias nrf905_dr_pin is pin_A2 -- Pin 11 for 14 pin DIP, external interrupt.
   alias nrf905_dr_pin_direction is pin_A2_direction  -- To DR of nRF905
   alias nrf905_external_interrupt_enable is INTCON_INTE
   alias nrf905_global_interrupt_enable is INTCON_GIE
   alias nrf905_external_interrupt_edge is OPTION_REG_INTEDG
   alias nrf905_external_interrupt_flag is INTCON_INTF
   alias nrf905_postive_interrupt_edge is TRUE
end if

-- nRF905 addresses. We use 4-bit addresses (default).
const dword NRF905_RX_ADDR_1 = 0x11223344  -- My address.
const dword NRF905_TX_ADDR_1 = 0x55667788  -- Address of device 1.
const dword NRF905_TX_ADDR_2 = 0xBBCCDDEE  -- Address of device 1.

-- We do not use the library default payload size (default is maximum of 32).
const byte NRF905_TX_PAYLOAD_SIZE = 25
const byte NRF905_RX_PAYLOAD_SIZE = 25
-- The RX buffer size must be equal to or bigger than the highest payload size.
const byte NRF905_RX_BUFFER_SIZE  = 25
include nrf905

-- Some text constants.
const byte start[] = "Test program for nRF905.\r\n"
const byte hello_1[] = "Hello World 1!"
const byte hello_2[] = "Hello World 2!"

-- Used variables.
var word timer
var byte counter, index, pipe
var byte device_to_send_to
var bit sending_data

-- Initialize the bRF905 module with the default values.
nrf905_init()
-- Set receiver address of this device.
nrf905_set_rx_address(NRF905_RX_ADDR_1)
-- Our module has a 16 MHz clock (init value is 20 MHz)
nrf905_set_crystal_clock(NRF905_CRYSTAL_CLK_16MHZ)
-- Set a different payload width for this program.
nrf905_set_rx_payload_width(NRF905_RX_PAYLOAD_SIZE)
nrf905_set_tx_payload_width(NRF905_TX_PAYLOAD_SIZE)
-- A little bit more power please.
nrf905_set_power_level(NRF905_POWER_LEVEL_MAX)

-- Show welcome message on the screen.
print_string(serial_hw_data,start)
print_crlf(serial_hw_data)

timer = 0
sending_data = FALSE
device_to_send_to = 1

nrf905_print_configuration_register()

forever loop
   -- Loop timer 1 ms.
   _usec_delay(1_000)

   -- Send a message to one of the devices and alternate devices..
   timer = timer + 1
   -- Wait 1 second before sending the next message.
   if (timer >= 1_000) then
      print_crlf(serial_hw_data)
      if (device_to_send_to == 1)
      then
         -- Send to first device.
         print_string(serial_hw_data,"Sending data to device 1 ... ")
         nrf905_set_tx_address(NRF905_TX_ADDR_1)
         nrf905_send_data(hello_1, count(hello_1))
         device_to_send_to = 2
      elsif (device_to_send_to == 2)
      then
         -- Send to second device.
         print_string(serial_hw_data,"Sending data to device 2 ... ")
         nrf905_set_tx_address(NRF905_TX_ADDR_2)
         nrf905_send_data(hello_2, count(hello_2))
         device_to_send_to = 1
      end if
      sending_data = TRUE
      timer = 0
    end if

   -- Print the transmission status and enable the receiver.
   if sending_data & nrf905_tx_ready() then
      -- Transmission done, check if successful.
      print_string(serial_hw_data,"Transmission Done! \r\n")
      print_string(serial_hw_data,"Enabling receiver ... \r\n")
      -- Enable receiver again.
      nrf905_power_up_rx()
      sending_data = FALSE
   end if

   -- Print the message from any of the 2 devices. Ignore the values 0x00 which
   -- can be added when the received message is shorter than the maximum payload.
   if nrf905_get_data() then
      print_crlf(serial_hw_data)
      print_string(serial_hw_data,"Receiving data: ")
      for NRF905_RX_PAYLOAD_SIZE using index loop
         if nrf905_rx_buffer[index] != 0x00 then
            serial_hw_data = nrf905_rx_buffer[index]
         end if
      end loop
      print_crlf(serial_hw_data)
  end if

end loop



The way it is connected to my pic:
Capture.JPG

And finally what it outputs:

Capture2.JPG

The library "nfR905.jal" is unchanged, I just added the status  return which is always 255
Why is frequency illegal?

I tried many many ways to make it run, but I'm a bit lost, since I don't undertand why it works for you...
I need a help !!!

Regards,
Gilles

Rob CJ

unread,
Feb 8, 2021, 12:56:47 PM2/8/21
to jal...@googlegroups.com
Hi Gilles,

Sorry to hear that.

I had a quick look at you schematic diagram but there is something that I do not understand. You have made connections to the module using port B but the interface pins in your software for the communication are all on port C (and one on A).

I am talking about these pin assignments in your program
-- nRF905 pin definition.
alias nrf905_spi_sck is pin_C0 -- Pin 10 for 14 pin DIP
alias nrf905_spi_sck_direction is pin_C0_direction -- To SCK of nRF905
alias nrf905_spi_sdi is pin_C1 -- Pin 9 for 14 pin DIP.
alias nrf905_spi_sdi_direction is pin_C1_direction -- To MISO of nRF905
alias nrf905_spi_sdo is pin_C2 -- Pin 8 for 14 pin DIP.
alias nrf905_spi_sdo_direction is pin_C2_direction -- To MOSI of nRFF905
alias nrf905_csn_pin is pin_C3 -- Pin 7 for 14 pin DIP.
alias nrf905_csn_pin_direction is pin_C3_direction -- To csn of nRF905
alias nrf905_txen_pin is pin_A5 -- Pin 2 for 14 pin DIP.
alias nrf905_txen_pin_direction is pin_A5_direction -- To txen of nRF905
alias nrf905_trx_ce_pin is pin_A4 -- Pin 3 for 14 pin DIP.
alias nrf905_trx_ce_pin_direction is pin_A4_direction  -- To (tx_)ce of nRF905

These aliases are still from the sample program. You have to change these aliases so that they match with your hardware schematig. Or am I missing something here?

Kind regards,

Rob


Van: jal...@googlegroups.com <jal...@googlegroups.com> namens bar...@gmail.com <bar...@gmail.com>
Verzonden: maandag 8 februari 2021 14:50
Aan: jallib <jal...@googlegroups.com>

bar...@gmail.com

unread,
Feb 9, 2021, 3:07:18 AM2/9/21
to jallib
Hi Rob,

thank you for your quick answer
Yes you're right, I made a mistake while posting (I was a bit tired ;-) , the correct code I tested with is this one:

-- nRF905 pin definition.
alias nrf905_spi_sck is pin_B3
alias nrf905_spi_sck_direction is pin_B3_direction -- To SCK of nRF905
alias nrf905_spi_sdi is pin_B1
alias nrf905_spi_sdi_direction is pin_B1_direction -- To MISO of nRF905
alias nrf905_spi_sdo is pin_B2
alias nrf905_spi_sdo_direction is pin_B2_direction -- To MOSI of nRFF905
alias nrf905_csn_pin is pin_A1
alias nrf905_csn_pin_direction is pin_A1_direction -- To csn of nRF905
alias nrf905_txen_pin is pin_B5
alias nrf905_txen_pin_direction is pin_B5_direction -- To txen of nRF905
alias nrf905_trx_ce_pin is pin_B4
alias nrf905_trx_ce_pin_direction is pin_B4_direction  -- To (tx_)ce of nRF905

the rest of the program remains unchanged.

As you can see, it seems that the module always "sees" something to receive... Also some parameters appear to be incorrect, but I don't know what to change.
Maybe there is something specific to add for the 18F45K22 ?

Regards,
Gilles

Rob CJ

unread,
Feb 9, 2021, 1:52:23 PM2/9/21
to jal...@googlegroups.com
Hi Gilles,

I can give it a try this weekend. I do not have a 18f45k22 but I may have a 18f25k22 (same family).

One more question. This device operates at 3.3 Volt and in your schematic diagram you connect it to VCC and directly to the PIC but for that your PIC needs to work at 3.3. Volt too.

If the PIC is operating at 5 Volt you need to have level shifters between the PIC and the nRF905. Also see the blog post: JAL Library for the nRF905 transceiver module | Just Another JAL Website (justanotherlanguage.org)

I hope VCC is not +5Volt. If so then you may have damaged the device. Let me know if this is the case or not.

I will let you know as soon as I have tested it with your program.

Kind regards,

Rob


Verzonden: dinsdag 9 februari 2021 09:07

Gilles BARTHELEMY

unread,
Feb 9, 2021, 2:27:32 PM2/9/21
to jal...@googlegroups.com
Hi Rob, 

Yes, the whole system operates at 3v3.
I tried to make it work on a manufactured prototype (it's a part of a bigger project), on a development board, and even a breadboard, with no success... I buyed and tried several modules (the same as yours) but no way  :-(


Rob CJ

unread,
Feb 10, 2021, 1:56:10 PM2/10/21
to jal...@googlegroups.com
Hi Gilles,

I started building up the circuit again but I saw I had not made a schematic diagram so I did that first. After making this I compared my diagram with yours and found a difference.

If I saw it right and with the aliases that you mentioned it looks as if you swapped the MISO and MOSI pins of the SPI interface.

I attached my schematic diagram (hopefully correct but I think so). Can you compare your aliases for sdi and sdo and compare it with the hardware connections to the nRF905? 

Thanks.

Kind regards,

Rob


Verzonden: dinsdag 9 februari 2021 20:27
nRF905.pdf

bar...@gmail.com

unread,
Feb 21, 2021, 3:51:17 PM2/21/21
to jallib
Hi Rob

Well, how to say... I agree, it's much better with pins connected the right way !! 
I'm a bit ashamed of this so obvious mistake. But your sight wasn't mine ;-)
That said, even if I can now get an answer of each module thru the console, I couldn't have them talk together; both with exactly the same init...
I ordered a few new modules in case I fried those, I will test as soon as they arrive.
Thank you for your big help.

Regards
Gilles

Rob CJ

unread,
Feb 22, 2021, 12:35:06 PM2/22/21
to jal...@googlegroups.com
Hi Gilles,

It could happen to anybody.

Just in case. Make sure that the tansmit address and receive address are correct 🙂, so the transmit address of one is the receive address of the other and the other way around. 

So you can't use exactly the same program on two devices since the addresses must be swapped (at least if you want these two devices to communcate with each others).

If it still does not work let me know.

Kind regards,

Rob


Verzonden: zondag 21 februari 2021 21:51
Reply all
Reply to author
Forward
0 new messages