NRF52840 - can't define char array longer than 8 chars

Hi, I’m experiencing some weird behavior when I define arrays. The code compiles. When I download it to NRF52840, the following happens:

char buf[8] = {“$PMTK00”}; //works
char buf[9] = {“$PMTK000”}; //does not work
char buf[14] = {“$PMTK000*32\r\n”} //does not work

char buf2[2] = {‘$’, ‘P’}; //works
char buf2[6] = {‘$’,‘P’,‘M’,‘T’,‘K’,‘0’};//works
char buf2[7] = {‘$’,‘P’,‘M’,‘T’,‘K’,‘0’,‘0’}; //does not work
char buf2[8] = {‘$’,‘P’,‘M’,‘T’,‘K’,‘0’,‘0’,‘0’}; //does not work
char buf2[13] = {‘$’,‘P’,‘M’,‘T’,‘K’,‘0’,‘0’,‘0’,‘*’,‘3’,‘2’,‘\r’,‘\n’}; //does not work

By not working I mean that NRF52840 doesn’t appear on nrfConnect and doesn’t show any life signs so I guess there’s an internal error. I can’t debug the chip, I have no UART.

Does anybody have an idea what causes this chaotic behavior and how can I fix it? Thanks

Hello,

there are some rules about string and char types, I think. Chars must be between two single quotes (') and not between two double quotes (")

  • string - “ABC”
  • char - ‘C’

Character sequences - C++ Tutorials (cplusplus.com)

BR, Jan

I modified the array to uint8_t and it works.