Modify RF24Network library to support Cytron ARM Cortex M0

Talk about Arduino board, sheilds. Sharing Arduino projects, program, problems, solutions, suggestions..... many more, all are welcome.

Modify RF24Network library to support Cytron ARM Cortex M0

Postby zxlee » Mon Nov 28, 2016 9:30 pm

Hi,

I am currently working on a project to interface nRF24L01 with Cytron ARM Cortex M0. I knew that nRF24L01 will be compatible with this board, however, in terms of the library I am using (RF24 and RF24Network), there is no support for Cytron ARM board. You can refer to the attachment on the error message.

May I know if there is a workaround for this problem or how should I modify the library to enable this support? Any links to understand how to modify Arduino library for new board support would be helpful too.

Thanks.
Zx
Attachments
Cytron ARM.JPG
Zxlee
Enjoys learning Electronics and Programming.

http://iamzxlee.wordpress.com/
zxlee
Newbie
 
Posts: 12
Joined: Thu Nov 14, 2013 1:34 am

Re: Modify RF24Network library to support Cytron ARM Cortex

Postby bengchet » Tue Nov 29, 2016 3:38 pm

Hi,

You can give us the link for these 2 libraries. We will try to see what modifications can be made to make it CT-ARM compatible.
bengchet
Moderator
 
Posts: 237
Joined: Tue Aug 25, 2015 8:29 am

Re: Modify RF24Network library to support Cytron ARM Cortex

Postby zxlee » Tue Nov 29, 2016 5:03 pm

So it is still possible to use the library on CT-ARM?

The library that I am trying to use are
1. https://github.com/TMRh20/RF24
2. https://github.com/TMRh20/RF24Network

Thanks ;)
Zxlee
Enjoys learning Electronics and Programming.

http://iamzxlee.wordpress.com/
zxlee
Newbie
 
Posts: 12
Joined: Thu Nov 14, 2013 1:34 am

Re: Modify RF24Network library to support Cytron ARM Cortex

Postby bengchet » Wed Nov 30, 2016 4:18 am

Hi,

You can go to RF24.cpp file and replace
CODE: SELECT_ALL_CODE
      _SPI.setClockDivider(SPI_CLOCK_DIV2);


with
CODE: SELECT_ALL_CODE
#ifndef __NUC131__      
      _SPI.setClockDivider(SPI_CLOCK_DIV2);
#endif


This is just a temporarily fix for compilation. I have just checked the RF24 source code, the minimum SPI clock rate is same as the SPI clock rate set by CT-ARM SPI library. So in this case setClockDivider is not really needed. However, you still need to test the performance. With SPI_CLOCK_DIV2 settings, clock rate is double the default one.
bengchet
Moderator
 
Posts: 237
Joined: Tue Aug 25, 2015 8:29 am

Re: Modify RF24Network library to support Cytron ARM Cortex

Postby zxlee » Fri Dec 02, 2016 12:15 am

Hi,

Thanks, after modify the library, I can compile without any error. However, if I tried to run the simple example from RF24 library, getting started, it just won't work. I am using a CT-ARM to talk with another Arduino, both with the radio to verify if the library is working. Apparently, it show its not. If I use it to talk between two Arduino, they work perfectly.
Zxlee
Enjoys learning Electronics and Programming.

http://iamzxlee.wordpress.com/
zxlee
Newbie
 
Posts: 12
Joined: Thu Nov 14, 2013 1:34 am

Re: Modify RF24Network library to support Cytron ARM Cortex

Postby bengchet » Fri Dec 02, 2016 11:55 am

Hi,

You can try check the connection. Make sure you connect SPI pins of NRF module to CT-ARM ICSP header (not D11, D12, D13 because they have no connection with SPI), connect SS to D10 of CT-ARM.

Regarding radio(pin1, pin2) in the program, if possible can you explain more about what are these pins used for. Is interrupt involved?
bengchet
Moderator
 
Posts: 237
Joined: Tue Aug 25, 2015 8:29 am

Re: Modify RF24Network library to support Cytron ARM Cortex

Postby zxlee » Fri Dec 02, 2016 5:39 pm

Great, I think you have found the cause of my problem. I use the SPI pin as if it was similar to standard Arduino. I didn't notice until I refer back the CT-ARM diagram. Thanks!! Let me try it out and share to you the outcome.

The radio(pin 1, pin 2) refers to the CE pin and CSN pin. The RF24 library by tmrh20 uses pin 7 for CE and pin 8 for CSN. The IRQ pin from nRF24L01 was not used in this case.
Zxlee
Enjoys learning Electronics and Programming.

http://iamzxlee.wordpress.com/
zxlee
Newbie
 
Posts: 12
Joined: Thu Nov 14, 2013 1:34 am

Re: Modify RF24Network library to support Cytron ARM Cortex

Postby zxlee » Wed Dec 07, 2016 8:30 am

I was able to communicate with the nRF24L01 after changing my SPI pin to the ISP connector. However, I faced another issue is that my Arduino is sending 10 bytes of payload to CT-ARM, however, CT-ARM will receive 12 bytes of payload. If I replace the receiver with Arduino, both sender and receiver will have the same amount of payload.

I was wondering will there be anything related to the AVR vs ARM architecture that could cause this different behaviour in RF24 library or the variable datatype in 8bit processor is different with 32bit processor?


I am using the helloword_tx and helloworld_rx examples from RF24Network library to verify this.
Zxlee
Enjoys learning Electronics and Programming.

http://iamzxlee.wordpress.com/
zxlee
Newbie
 
Posts: 12
Joined: Thu Nov 14, 2013 1:34 am

Re: Modify RF24Network library to support Cytron ARM Cortex

Postby bengchet » Thu Dec 08, 2016 9:57 am

Hi,

In fact in this case, if you are getting larger size, it is common. It is due to compiler, struct padding and alignment issues. For AVR compiler, let's say you have one variable long(4 bytes), one variable long (4 bytes) and one variable int(2 bytes) ordered in this manner, it gives size of struct size 4+4+2 = 10.

However in ARM (we are using GCC compiler in this case), variable int has 4 bytes. So in total the struct size will be 4+4+4 = 12 instead. So it is normal you are getting this issue with CT-ARM but I believe you have no problem getting the same data, am I right?

You can try use sizeof(variable type) in your program and see the comparison between CT-ARM and AVR boards. If you wish to use 2 bytes in CT-ARM, use short instead of int.

Another issue you will be facing will be struct padding and alignment issues, this will arise if you are using mixed type of variables(int, char, long) in one struct, you will get different results between CT-ARM and AVR boards.

To solve this issue just modify the struct into following just in case:

struct __attribute__((__packed__)) payload_t{
*/your variables*/
};

In AVR boards, structs will be packed automatically during compilation so you don't need to put __attribute__(( __packed__)) in Arduino program.

For more info, you can refer to these websites:
https://en.wikipedia.org/wiki/Data_structure_alignment
http://stackoverflow.com/questions/29618439/what-is-the-size-of-integer-in-8-bit-16-bit-32-bit-processors-microcontrollers
http://stackoverflow.com/questions/4306186/structure-padding-and-packing

Have fun learning and experimenting!

Edit:: One common way to avoid confusion between datatypes is using int[x]_t or uint[x]_t, for example if you want to use unsigned variables with 2 bytes, then using uint16_t. Check if it works.
bengchet
Moderator
 
Posts: 237
Joined: Tue Aug 25, 2015 8:29 am

Re: Modify RF24Network library to support Cytron ARM Cortex

Postby zxlee » Fri Dec 09, 2016 12:54 pm

I can understand your first statement where the size of variable, in this case, int is different between ARM and AVR compiler. That was what I first suspect when I received different payload size. Due to this, the data I received from Arduino using CT-ARM was incorrect.

So do you mean that let say my Arduino is sending a int16_t to CT-ARM, my CT-ARM should identify it as a short or can I also declare it in int16_t, will it interpret correctly?

And the last thing is just to modify struct, hopefully this can solve the issue im facing. Thanks.
Zxlee
Enjoys learning Electronics and Programming.

http://iamzxlee.wordpress.com/
zxlee
Newbie
 
Posts: 12
Joined: Thu Nov 14, 2013 1:34 am


Return to Arduino Based

Who is online

Users browsing this forum: No registered users and 5 guests

cron