From: Nathael Pajani Date: Thu, 17 Sep 2015 19:15:45 +0000 (+0200) Subject: Do not change state if already in the required one Place config registers in address... X-Git-Url: http://git.techno-innov.fr/?a=commitdiff_plain;h=ff21522fee90da4fb3c5d1c574f1e15ab0725c45;p=soft%2Flpc122x%2Fcore Do not change state if already in the required one Place config registers in address order for readability and update comments --- diff --git a/extdrv/cc1101.c b/extdrv/cc1101.c index 5f81055..0d3746f 100644 --- a/extdrv/cc1101.c +++ b/extdrv/cc1101.c @@ -147,16 +147,22 @@ uint8_t cc1101_read_pkt_status(void) /* Change Current mode / status to RX */ void cc1101_enter_rx_mode(void) { - cc1101_send_cmd(CC1101_CMD(state_idle)); + uint8_t status = (cc1101_read_status() & CC1101_STATE_MASK); + if (status != CC1101_STATE_RX) { + if ((status != CC1101_STATE_FSTON) && (status != CC1101_STATE_TX)) { + cc1101_send_cmd(CC1101_CMD(state_idle)); + } + } cc1101_send_cmd(CC1101_CMD(state_rx)); } static uint8_t cc1101_enter_tx_mode(void) { - uint8_t status = 0; - status = (cc1101_read_status() & CC1101_STATE_MASK); + uint8_t status = (cc1101_read_status() & CC1101_STATE_MASK); if (status != CC1101_STATE_TX) { - cc1101_send_cmd(CC1101_CMD(state_idle)); + if ((status != CC1101_STATE_FSTON) && (status != CC1101_STATE_RX)) { + cc1101_send_cmd(CC1101_CMD(state_idle)); + } cc1101_send_cmd(CC1101_CMD(state_tx)); } /* Wait until chip is in Tx state */ @@ -417,13 +423,14 @@ static uint8_t rf_init_settings[] = { /* Frequency synthesizer control - 0x0B .. 0x0C - FSCTRL1..0 */ CC1101_REGS(freq_synth_ctrl[0]), 0x0C, /* Used for ?? IF: 304.6875 KHz */ + CC1101_REGS(freq_synth_ctrl[1]), 0x00, /* Reset value */ /* Carrier Frequency control - FREQ2..0 : Fcarrier == 867.999939 MHz */ CC1101_REGS(freq_control[0]), 0x21, /* 0x216276 == Fcarrier * 2^16 / Fxtal */ CC1101_REGS(freq_control[1]), 0x62, /* == approx(868 MHz) * 65536 / 26 MHz */ CC1101_REGS(freq_control[2]), 0x76, - /* Modem configuration - MDMCFG4..0 */ + /* Modem configuration - MDMCFG4..0 - 0x10 .. 0x14 */ /* MDMCFG4..3 : RX filterbandwidth = 541.666667 kHz and Datarate = 249.938965 kBaud */ CC1101_REGS(modem_config[0]), 0x2D, CC1101_REGS(modem_config[1]), 0x3B, @@ -435,12 +442,10 @@ static uint8_t rf_init_settings[] = { /* Modem deviation : DEVIATN */ CC1101_REGS(modem_deviation), 0x62, /* Deviation = 127 kHz */ - /* Front End Rx/Tx config : use defaults */ -// CC1101_REGS(front_end_rx_cfg), 0x56, -// CC1101_REGS(front_end_tx_cfg), 0x10, - /* Main Radio Control State Machine Configuration - MCSM2..0 */ - CC1101_REGS(radio_stm[1]), 0x3F, /* CCA mode if RSSI below threshold, Stay in RX, Go to RX */ + /* Main Radio Control State Machine Configuration - MCSM2..0 - 0x16 .. 0x18 */ + CC1101_REGS(radio_stm[0]), 0x07, /* Use default */ + CC1101_REGS(radio_stm[1]), 0x3F, /* CCA mode if RSSI below threshold unless Rx, Stay in RX, Go to RX */ CC1101_REGS(radio_stm[2]), 0x18, /* PO timeout 149-155us, Auto calibrate from idle to rx/tx */ /* Frequency Offset Compensation configuration - FOCCFG */ @@ -452,6 +457,12 @@ static uint8_t rf_init_settings[] = { CC1101_REGS(agc_ctrl[1]), 0x00, /* LNA 2 gain decr first, Carrier sense relative threshold disabled */ CC1101_REGS(agc_ctrl[2]), 0xB0, /* Medium settings, 24 samples wait time, normal op. */ + /* Wake on radio : use defaults */ + + /* Front End Rx/Tx config */ + CC1101_REGS(front_end_rx_cfg), 0xB6, + CC1101_REGS(front_end_tx_cfg), 0x10, + /* Frequency synthesizer calibration - 0x23 .. 0x26 - FSCAL3..0 */ CC1101_REGS(freq_synth_cal[0]), 0xEA, CC1101_REGS(freq_synth_cal[1]), 0x2A,