Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Software ack reponse too quick on nRF24 #1134

Open
Yveaux opened this issue May 20, 2018 · 5 comments
Open

Software ack reponse too quick on nRF24 #1134

Yveaux opened this issue May 20, 2018 · 5 comments

Comments

@Yveaux
Copy link
Member

Yveaux commented May 20, 2018

MySensors Version: 2.2.0
Hardware:

  • STM32 BluePill @72MHz (Serial) Gateway + any type of node
  • nRF24 radios

What I'm doing: Bench marking different gateways (currently a STM32 Serial & Ehternet MQTT)

Problem Encountered: Sending loads of messages from the node to the gateway. Each message send from the node requests an ack'd from the gateway.

  • When I Enable #define MY_DEBUG in the sketch everything works flawlessly and high message rates can be achieved without any loss of hardware (the automatic one from the nRF24 radio) or software acknowledge from the gateway.
  • When I Remove #define MY_DEBUG in the sketch I suddenly have loads of messages which do not appear to receive a hardware or software acknowledge from the gateway.

Expected Cause:

  • It appears that the automatic hardware ack from the gateway radio gets too little time to complete due to the requested software acknowledge to be transmitted. I.e. without the additional debug messages (=delay) present in the code a high clock speed microcontroller (like the STM32) is too fast in pushing a software ack to the radio before it can properly complete the hardware ack message.

According to the nRF24 datasheet (section 7.9) there must at least be 130us between the completion of the transmitted message and the hardware ack. response. On top of the 130us we also need some time to transmit the actual ack message. This total time must at < ARD (Auto Retransmit Delay), which is configures to be 1500us for MySensors.

So in MyTransport.cpp in transportProcessMessage just before the (void)transportSendRoute(_msgTmp) I added a delay of 1500uS and it all worked reliably again (successful hardware and software ack's and significant reduction of auto re-transmits of 16 times). This delay can actually be smaller than the 1500us as there is of course some time consumed by all the other tasks (still appeared to work properly with only 150us).

@Swiftnesses
Copy link

This explains some of my issues, hope it can be implemented soon!

@Yveaux
Copy link
Member Author

Yveaux commented Jul 28, 2018

Confirmed issue, using blue pill and atmega328 node.

If gateway does not have MY_DEBUG defined the ARC count on the node goes up quickly.

Very simple workaround is to add delayMicroseconds(1500) at the start of RF24_sendMessage() in RF24.cpp.
This assures any hardware acks have been sent before a new packet is sent.

If the delay is moved just after RF24_stopListening() the ARC count goes up again.

@cimba007
Copy link

Just for reference .. I had a similar timing issue with a fast gateway and slow nodes

#578

@mfalkvidd
Copy link
Member

Nice work Yveaux.

This seems to be the relevant part of the datasheet:
image

Doesn't this mean that we can check the TX_DS bit in the STATUS register for successful transmission and MAX_RT bit in the STATUS register for failed transmission? If IRQ is used, it will be triggered when either TX_DS or MAX_RT are set, so there is no need to delay for an arbitrary amount of time.

When checking the code, I see that we are in fact checking TX_DS and MAX_RT, but we are not using IRQ and the timeout is hardcoded to 65535 executions of the loop with the comment // timeout value after successful TX on 16Mhz AVR ~ 65500, i.e. msg is transmitted after ~36 loop cycles.

This timeout will certainly be too short on fast mcus.

@mfalkvidd
Copy link
Member

mfalkvidd commented May 12, 2019

Sorry for the confusion. The spi speed is 2MHz regardless of mcu so this timeout doesn't change unless the sketch developer overrides spi speed. You can disregard my previous comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants