stm32duino / S2-LP

Arduino library to support S2-LP sub-1GHz transceiver
BSD 3-Clause "New" or "Revised" License
10 stars 7 forks source link

Logix error in S2LP::S2LPCsmaSetCcaLength #11

Closed rlourette closed 3 years ago

rlourette commented 3 years ago

In the code for S2LP::S2LPCsmaSetCcaLength(uint8_t xCcaLength), it is missing the shift to the upper 4 bits of the register. See S2LPCsmaGetCcaLength method.

/**
 * @brief  Set the CCA length.
 * @param  xCcaLength the CCA length (a value between 1 and 15 that multiplies the CCA period).
 *     This parameter can be any value of @ref CsmaLength.
 * @retval None.
 */
void S2LP::S2LPCsmaSetCcaLength(uint8_t xCcaLength)
{
  uint8_t tmp;
  s_assert_param(IS_CSMA_LENGTH(xCcaLength));

  S2LPSpiReadRegisters(CSMA_CONF0_ADDR, 1, &tmp);

  tmp &= ~CCA_LEN_REGMASK;
  tmp |= xCcaLength;

  g_xStatus = S2LPSpiWriteRegisters(CSMA_CONF0_ADDR, 1, &tmp);

}

/**
 * @brief  Return the CCA length.
 * @param  None.
 * @retval uint8_t CCA length.
 */
uint8_t S2LP::S2LPCsmaGetCcaLength(void)
{
  uint8_t tmp;

  g_xStatus = S2LPSpiReadRegisters(CSMA_CONF0_ADDR, 1, &tmp);

  return (tmp >> 4);
}
cparata commented 3 years ago

Hi @rlourette , you are right. It is a bug. I will fix it immediately. Thanks a lot for your contribution. Best Regards, Carlo

cparata commented 3 years ago

Fixed on the master repository