cancel
Showing results for 
Search instead for 
Did you mean: 

Undefined response from BlueNRG

Andrey Semenov
Associate II
Posted on November 28, 2017 at 06:56

Hello!

I have a problem with BlueNRG chip (old one, NOT BlueNRG-MS). I made a custom PCB with STM32F407VGT6 and BlueNRG on it and try to setup. In MCU test firmware there aren't any functions that used for commutication with BLE chip. When I turn on my device, I always notice that there is a VCC voltage on IRQ pin of BlueNRG. According to documentation this means that there is some data to read. Strange! What data should I read, if I haven't sent any command?.. Ok, I read it. First send a read header and recieve this: status = 0x02, write buffer = 0x3F and read buffer = 0x After that I get this array of bytes: 0x04, 0xFF, 0x03, 0x01, 0x00, 0x01. The first question is: what is it? How should I interpret it?

Next, I want to send some command and watch response. I tested HCI_Reset, HCI_Read_Local_Version_Information, HCI_Read_Local_Supported_Commands, HCI_LE_Read_Buffer_Size... Every time I get this response:

1. Header is: status = 0x02, write buffer = 0x3F and read buffer = 0x04 2. Response body: 0x04, 0x10, 0x01, 0x00

Second question is: what does this response mean? Why when I send any command, I always get this?

This is my C++ code for transmiting and recieving data:

struct Header
{
 uint8 status;
 uint16 writeBuffer;
 uint16 readBuffer;
};
Header getHeader(uint8 type)
{
 uint8 status = SPIwriteAndRead(type); // read status
 uint16 writeBuffer = SPIwriteAndRead(0x00) | (SPIwriteAndRead(0x00) << 8); // read writeBuffer
 uint16 readBuffer = SPIwriteAndRead(0x00) | (SPIwriteAndRead(0x00) << 8); // read readBuffer
 return {status, writeBuffer, readBuffer};
}
void readResponse(uint8 *buffer, uint16 size)
{
 for(uint16 i = 0; i < size; i++)
 buffer[i] = SPIwriteAndRead(0x00); // send dummy byte and recieve data
}
void sendCommand(uint8 *data, uint8 size)
{
 for(uint8 i = 0; i < size; i++)
 SPIwriteAndRead(data[i]); // send data byte
}
int main()
{
 initMCU(): // init GPIO, SPI, RCC...
 
 //---- read incomming message
 uint8 responseBuffer[127] = {0};
 waitForEvent(); // wait when IRQ pin of BlueNRG becomes high
 
 while(true)
 {
 setCSLow(); // begin transmission
 Header header = getHeader(0x0B); // send Read header
 if(header.status == 0x02 && header.readBuffer > 0) // check if BlueNRG is ready and has something in its read buffer
 {
 readResponse(responseBuffer, header.readBuffer); // read data
 setCSHigh(); // finish commutication
 break;
 }
 else setCSHigh(); //conditions don't match, finish commutication
 }
 
 //---- at this moment responseBuffer contains 0x04, 0xFF, 0x03, 0x01, 0x00, 0x01;
 
 //---- let's execute HCI_Read_Local_Version_Information
 setCSLow(); // begin transmission
 Header header = getHeader(0x0A); // send Write header
 if(header.status == 0x02) // check if BlueNRG is ready
 {
 sendCommand({0x10, 0x01, 0x00}, 3); // opcode = 0x1001 and length of parameters = 0
 setCSHigh(); // finish commutication
 }
 else 
 {
 // error...
 setCSHigh(); // finish commutication
 while(true);
 }
 
 uint8 commandbuffer[127] = {0};
 waitForEvent(); // wait when IRQ pin of BlueNRG becomes high
 
 while(true)
 {
 setCSLow(); // begin transmission
 Header header = getHeader(0x0B); // send Read header
 if(header.status == 0x02 && header.readBuffer > 0) // check if BlueNRG is ready and has something in its read buffer
 {
 readResponse(commandbuffer, header.readBuffer); // read data
 setCSHigh(); // finish commutication
 break;
 }
 else setCSHigh(); //conditions don't match, finish commutication
 }
 
 //---- at this moment commandbuffer contains 0x04, 0x10, 0x01, 0x00;
 
 while(true);
}�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

I think I miss something... Help me please!

#bluenrg #response
1 REPLY 1
Andrey Semenov
Associate II
Posted on December 02, 2017 at 13:13

According to 'AN4494 Bringing up the BlueNRG and BlueNRG-MS devices' these bytes - 0x04, 0xFF, 0x03, 0x01, 0x00, 0x01 mean a Blue_Initialized_Event. And we see them - it is very good.

If I understood correctly these bytes  0x04, 0x10, 0x01, 0x00 - mean a hardware error with code 0 - SPI framing error (UM1865 BlueNRG-MS Bluetooth LE stack application command interface (ACI)).

My SPI setup is correct:

CR1 = 0x00000344

SR = 0x00000002

CRCPR = 0x00000007

I2SPR = 0x00000002

Other registers are = 0

I ask you: WHY your IC gives an error?

I tested two IC and result is the same!