主设备为280049
通过下方代码读取寄存器值,总是会读到0x7FFF的值,
但是如果在第25行 return sendCommand(OPCODE_NULL); 添加断点,则程序能正常读到寄存器值
请问是否在发送Command后需要等待一段时间才可以指定的应答数据?
uint16_t readSingleRegister(uint8_t address) { /* Check that the register address is in range */ assert(address < NUM_REGISTERS); // Build TX and RX byte array #ifdef ENABLE_CRC_IN uint8_t dataTx[8] = { 0 }; // 2 words, up to 4 bytes each = 8 bytes maximum uint8_t dataRx[8] = { 0 }; #else uint8_t dataTx[4] = { 0 }; // 1 word, up to 4 bytes long = 4 bytes maximum uint8_t dataRx[4] = { 0 }; #endif uint16_t opcode = OPCODE_RREG | (((uint16_t) address) << 7); uint8_t numberOfBytes = buildSPIarray(&opcode, 1, dataTx); // [FRAME 1] Send RREG command spiSendReceiveArrays(dataTx, dataRx, numberOfBytes); // // [FRAME 2] Send NULL command to retrieve the register data // registerMap[address] = sendCommand(OPCODE_NULL); // return registerMap[address]; return sendCommand(OPCODE_NULL); }