My next step on the Brick Buddy 3 code development was to implement the Bluetooth Interface. The Brick Buddy 3 uses a RN4871 instead of the RN4020. I was hoping that the change over was going to be simple, but that does not look like what will happen.
My plan was to use a Mikroe Click Board with an RN4871 on it. I also have one with an RN4870, which is just bigger version with more I/O pins. You can see the RN4871 in the picture above on the left. Well the best laid plans, things did not go as planned. After several failed starts at communications, I finally managed to get Tx/Rx connected. The RN4871 reset line also worked as advertised, but the system would reboot itself randomly or sometimes continuously. In the beginning I had just connected the serial port of the RN4871 to FTDI serial to USB converter and used TeraTerm to watch the RN4871 output. The %REBOOT% would show up every few seconds.
Searching the Internet this seemed to be an issue with earlier firmware versions. Also the RN4871 seemed to be sensitive to voltage ripple. So I did two things to hopefully improve performance. First I upgraded the firmware to 1.42. But that did not seem to do much improvement. So I backed down to 1.41 and there appeared to be improvement. Next I had a 10uF capacitor across Vcc and GND, right on the click board. The multiple resets went away and everything seemed to be more stable. Which one did it, not sure, but it needed the firmware upgrade. While this picutre is not very good and my soldering was below average on this, you can see the capacitor across the two pins.
With a stable system I started walking through the code I had been using for the RN4020 with modifications for the RN4871. It would always hang on the first command. I started stepping through the command and the while loop would not iterate. It always sent the same character to the RN4871. No matter how I wrote the code, it would not iterate or would iterate by random numbers. I changed the variables to different types, nothing matter. First I suspected the ISR was changing things. But that was not the case. After a day of this, I decided to install every Pack available for MPLAB 6.00. and for the PICKit4. Most of them installed, then said they do not apply. But whatever I did, the loop started iterating correctly. I was then able to walk through the command list and could watch the RN4871 respond to each. Then I used a generic BTLE tool on my phone to see that the RN4871 was correctly advertising all of the characteristics.
Now it became obvious that a parser was needed. Different commands result in different ASCII responses. Thus this is very similar to the old Hayes AT modem. Looking around I finally found a parser that was generated by the MPLAB Code Configurator, that was a start at this. It can be found on Github. This is where I stopped and moved on to ohter things. If time permits I will come back to this and see if I can get something working in a day or two.
No comments:
Post a Comment