Atmega328 UART connection to a RN4020 Bluetooth

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello. 

I have been working with the Microchip Bluetooth Low Energy RN4020 and trying to include a microcontroller. We decided to use ATMEGA328 and communicate to the BLE through UART, which is supported by both devices. Sadly we are not succeeding. The BLE doesn’t seem to understand different ASCII commands sent by Atmega328 and when we try to read the received message on the atmega328 from the BLE, we see some unexpected ASCII responses.

After different trials, we are asking ourselves that we may need to do some logic level shifter. We may believe this because Atmega328 is a CMOS family chip (even though we are using 3.3V as VDD for it) and the RN4020 uses a UART with “3.3V TTL line” (taken from the RN4020 datasheet). We haven't found someone working with an ATMEL (AVR) chip with this Microchip BLE.

Can someone try to explain me what do they mean with a 3.3V TTL line? Are we able to connect these two devices without a logic level shifter?.

 

Greetings, 

Fernando

This topic has a solution.

Last Edited: Fri. Oct 23, 2015 - 05:53 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

FerBLE wrote:

Can someone try to explain me what do they mean with a 3.3V TTL line? Are we able to connect these two devices without a logic level shifter?.

 

Yes.

 

I feel a bit queasy trying to help with a Microchip part, I have no fond memory of working with their parts.  I did a "find" for  "TTL" on the BLE data sheet and did not find your reference.

TTL is an old term likely relating to direct or raw uC pin interface, not RS232 levels.  By looking at the schematic in the BLE documentation, the PIC uC inteface is direct to BLE, so AVR connection would be similar.

 

Since you are having problems, have you checked that AVR TX goes to BLE RX, and AVR RX goes to BLE TX.  Most communications issues are related to incorrect baud rate settings.

 

 

It all starts with a mental vision.

Last Edited: Fri. Oct 9, 2015 - 01:40 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you for your fast reply. And I appreciate your help a lot because even though it is related with a Microchip device, I’m trying to work with an Atmega microcontroller too.

 

KitCarlson wrote:

 

I did a "find" for  "TTL" on the BLE data sheet and did not find your reference.

 

I'm sorry. My mistake here. It is not the datasheet, it is the "RN4020 Bluetooth® Low Energy Module User’s Guide" page 17, where they say “The line is 3.3V TTL” on the UART. I have checked both pdfs a lot and I have found the User guide to be a lot more useful.

 

 

KitCarlson wrote:

  By looking at the schematic in the BLE documentation, the PIC uC inteface is direct to BLE, so AVR connection would be similar.

 

Since you are having problems, have you checked that AVR TX goes to BLE RX, and AVR RX goes to BLE TX.  Most communications issues are related to incorrect baud rate settings.

 

 

We have reviewed a lot about the UART configuration from both devices. Due to the BLE device having a factory baud rate of 115200 bps, we decided to set the Atmega328 CPU frequency (F_CPU) to 3.6864 MHz just to get 0% error at 115.2k baud rate with an UBRRn of 1 (Asynchronous Normal mode -> U2Xn = 0) [page 201 from atmega328’s datasheet].  

As you said, the PIC microcontroller and BLE connections seem pretty normal, so we thought an AVR should connect the same way. Taking in mind we are working with an Atmega328PU (DIP Version), I can explain how we made the connections. We tried to connect with and without Hardware Flow Control from the BLE (even though our atmega doesn’t have defined RTS or CTS pins) as follows:

Without Hardware Flow control we connected:

  • Atmeg328 UART RXD (Pin 2) with RN4020 UART_TX  (Pin 5).
  • Atmega328 UART TXD (Pin 3) with RN4020 UART_RX (Pin 5).

With Hardware Flow Control enabled on the BLE, we connected:

  • RN4020’s CTS input pin to GND.
  • RN4020’s RTS output connected to an General I/O pin from the Atmega just to check if it is LOW level just before sending some commands from Atmega to RN4020.

With these configurations we weren’t able to succeed in the integration of both devices. I can show you more details of what we have tried, such as implemented code.

 

Thank you again,
Fernando

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Welcome to AVRFreaks Fernando.

 

Do you have a 3.6864 MHz crystal connected to your Mega328? What are your fuse settings? Have you checked that the chip is actually running at 3.6864 MHz?

 

 

Cheers,

 

Ross

 

Ross McKenzie, Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

UART baud rate is often measured by transmitting "U" in a loop, while observing bit timing with scope.

It all starts with a mental vision.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Could you show your UART code ?

And of course FAQ#3; did you do any test to check the real cpu clock ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello.

Apparently we missed some steps on a tutorial we were following. We missed all relating with changing internal or external clock (including fuse setting) of the microcontroller and just changed the F_CPU in the Makefile (at WinAVR). We are new with programming microcontrollers.

 

We checked atmega324’s datasheet (at Clock Generation) and changed the low bit fuse. We set the microcontroller frequency to 8Mhz and a baud rate of 9600bps. We then changed BLE baud rate to 9600bps on the Teraterm, connected through PICTAIL’s USB-to-UART mode.  With these settings we were able to connect both devices.

Thank a lot for your help,
Fernando

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi FerBLE,

I am planning to use the RN4020 module with atmega64 chip, I didn't set up the test yet but feel like I may have some issue that you had. 

Is there any possible way that I could get some help from you in the future? 

What tutorial you have had when you do the design?

 

Thanks  a lot.