I’m using an Atmega328p which is communicating with a Bluegiga BLE113 and I’m getting unexpected behaviour. It’s only after a couple days of debugging that I realised that it might be a memory issue. The C library that implements the API to communicate with the BLE113 is very large and I’m thinking that it eats up all my Atmega’s RAM (it contains a lot of global/static variables, like huge arrays of structures). My code works fine when I remove parts of the library so I’m thinking it’s a memory problem. It is eventually my intention to include only those parts of the API that I actually use in my application, in which case the memory problem would disappear. But it would be nice to have access to the full library during development.
I used avr-size to get some memory information about my application and it returned:
AVR Memory Usage
Program: 10062 bytes
(.text + .data + .bootloader)
Data: 3752 bytes
(.data + .bss + .noinit)
Am I right in assuming that the ‘Program’ part is kept on my flash memory and the ‘Data’ part is the RAM usage? Because this would mean that my application needs 3.7kB of RAM which is a lot more than the 2kB the Atmega actually has. So in short my question is: is the shortage of RAM the reason that my code is behaving unexpectedly or am I totally wrong? And if it is, is there a way to keep my RAM usage down without removing parts of the library?