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

config STack frame to used ack correctly #9

Open
pawelm87 opened this issue Jun 14, 2019 · 0 comments
Open

config STack frame to used ack correctly #9

pawelm87 opened this issue Jun 14, 2019 · 0 comments

Comments

@pawelm87
Copy link

Hi,
I try used STack frame and send ack to make sure that reciver got the packet. When I set all in spirit1 what is necessary I got this situation:
TX -> sends packet -> IRQ packet lost. This means that ACK packet from receiver don't recive packet.
RX -> gets packet and sends ACK -> IRQ packet read and IRQ packet sends.

my setting:
RX:

#include "mbed.h"
#include "mbed-trace/mbed_trace.h"
#include "SimpleSpirit1.h"
using namespace std;
#define MBED_TRACE_MAX_LEVEL TRACE_LEVEL_DEBUG
#define TRACE_GROUP "main"
#define SPIRIT_BUF_LEN (95)
DigitalOut led(LED1);
static SimpleSpirit1 &radio = SimpleSpirit1::CreateInstance(PIN_SPSGRF_MOSI,
PIN_SPSGRF_MISO,
PIN_SPSGRF_SCLK,
PIN_SPSGRF_IRQ,
PIN_SPSGRF_CS,
PIN_SPSGRF_SDN,
PIN_SPSGRF_LED);
static char read_buf[SPIRIT_BUF_LEN];
static volatile bool rx_done_flag = false;
static void callback_func(int event)
{
if(event == SimpleSpirit1::RX_DONE)
{
rx_done_flag = 1;
}
}
int main()
{
mbed_trace_init();
tr_info("---START---");
radio.attach_irq_callback(callback_func);
PktStackInit stackInit={
PKT_PREAMBLE_LENGTH_08BYTES, // preamble length in bytes
PKT_SYNC_LENGTH_4BYTES, // sync word length in bytes
0x1A2635A8, // sync word
PKT_LENGTH_VAR, // variable or fixed payload length
7, // length field width in bits (used only for variable length)
PKT_CRC_MODE_16BITS_2, // CRC mode
PKT_CONTROL_LENGTH_0BYTES, // control field length
S_DISABLE, // FEC
S_ENABLE // whitening
};
SpiritPktStackInit(&stackInit);
SpiritPktStackAutoAck(S_ENABLE, S_DISABLE);
radio.on();
SpiritTimerSetRxTimeoutCounter(0);
SpiritTimerSetRxTimeoutPrescaler(0);
SpiritTimerLdcrMode(S_DISABLE);
while (true) {
if(rx_done_flag)
{
memset(read_buf, 0, SPIRIT_BUF_LEN - 1);
read_buf[SPIRIT_BUF_LEN-1] = '\0';
rx_done_flag = false;
int ret = radio.read(read_buf, 58);//sizeof(read_buf));
printf("Received a packet Received string = '%s' (len=%d)\r\n", read_buf, ret);
SpiritIrqs pxIrqStatus;
SpiritIrqGetStatus(&pxIrqStatus);
}
}
}

TX:

#include "mbed.h"
#include "mbed-trace/mbed_trace.h"
#include "SimpleSpirit1.h"
using namespace std;
#define MBED_TRACE_MAX_LEVEL TRACE_LEVEL_DEBUG
#define TRACE_GROUP "main"
#define SPIRIT_BUF_LEN (60)
DigitalOut led(LED1);
static SimpleSpirit1 &radio = SimpleSpirit1::CreateInstance(PIN_SPSGRF_MOSI,
PIN_SPSGRF_MISO,
PIN_SPSGRF_SCLK,
PIN_SPSGRF_IRQ,
PIN_SPSGRF_CS,
PIN_SPSGRF_SDN,
PIN_SPSGRF_LED);
static char send_buf[SPIRIT_BUF_LEN] ={'S','P','I','R','I','T','1',' ','H','E','L','L','O',' ','W','O','R','L','D',' ','P','2','P',' ','D','E','M','O',' ','s','p','i','r','i','t','1',' ','h','e','l','l','o',' ','w','o','r','l','d',' ','p','2','p',' ','d','e','m','o'}; //29
static volatile bool tx_done_flag = false;
static void callback_func(int event)
{
if (event == SimpleSpirit1::TX_DONE)
{
tx_done_flag = 1;
}
}
int main()
{
mbed_trace_init();
tr_info("---START---");
radio.attach_irq_callback(callback_func);
PktStackInit stackInit={
PKT_PREAMBLE_LENGTH_08BYTES, // preamble length in bytes
PKT_SYNC_LENGTH_4BYTES, // sync word length in bytes
0x1A2635A8, // sync word
PKT_LENGTH_VAR, // variable or fixed payload length
7, // length field width in bits (used only for variable length)
PKT_CRC_MODE_16BITS_2, // CRC mode
PKT_CONTROL_LENGTH_0BYTES, // control field length
S_DISABLE, // FEC
S_ENABLE // whitening
};
SpiritPktStackInit(&stackInit);
SpiritPktStackRequireAck(S_ENABLE);
while(1)
{
radio.on();
tr_debug("radio on");
while(radio.is_receiving());
tr_debug("radio recive");
size_t curr_len = strlen((const char*)send_buf) + 1;
radio.send(send_buf, curr_len);
tr_debug("send");
uint8_t i = 10;
while(i--)
{
wait_ms(1);
uint8_t reg;
SdkEvalSpiReadRegisters(0xc1, 1, &reg);
tr_debug("spirit status %x", reg>>1);
if(reg>>1 == 0x33)
tr_debug("ready...");
break;
}
radio.off();
tr_debug("radio off");
if (tx_done_flag)
{
tx_done_flag = false;
tr_info("**Packet sent *** Sent string ='%s' (len=%d)", send_buf, strlen((const char)send_buf) + 1);
}
wait(10);
}
}

In TX I enable ACK field and in RX I enable autoack, but this don't work correctly. Interrupt sends data never occurd in TX. When I turn off RX and set retransmision feature, again never occurd IRQ max retransmision.

Someone can check my setting and tell my how correct config radio. What I need to set in register in RX and TX.

@pawelm87 pawelm87 changed the title config STack frame to send ack in frame config STack frame to used correct ack in frame Jun 14, 2019
@pawelm87 pawelm87 changed the title config STack frame to used correct ack in frame config STack frame to used ack Jun 14, 2019
@pawelm87 pawelm87 changed the title config STack frame to used ack config STack frame to used ack correctly Jun 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant