• AVR Freaks

AnsweredHot!EUSART sending null characters

Author
FabriC
New Member
  • Total Posts : 2
  • Reward points : 0
  • Joined: 2019/05/24 20:06:54
  • Location: 0
  • Status: offline
2019/07/19 18:26:36 (permalink)
0

EUSART sending null characters

Hi! I have a problem with my MCU EUSART. I've been testing it for learning purpuses and I was able to read and write single characters to and from the PC. After that I tried to send strings to the PC but I keep receiving null characters and I dont undestarnd why. Could anyone help me understand this? I'm using an MPLAB XPress Board with a PIC18F47K40. This is the main:
 
void main(void) {
    
    char *data="Hello world";
    
    eusart2_setup(9600);
    
    while(1) {
        eusart2_prints(data);
        __delay_ms(1000);
    }
    return;
}
 
 
And this is the function that I made:
 
void eusart2_prints(char *string) {
    while(*string) {
        while(!EUSART2_TXFLAG);
        EUSART2_SEND(*string);
        string++;
    }
}

 
Where EUSART2_TXFLAG and EUSART2_SEND are macros for the TX2IF and TX2REG respectively. If anyone could help me, I would really appreciate it!
#1
mbrowning
USNA79
  • Total Posts : 1537
  • Reward points : 0
  • Joined: 2005/03/16 14:32:56
  • Location: Melbourne, FL
  • Status: offline
Re: EUSART sending null characters 2019/07/22 11:29:03 (permalink) ☼ Best Answerby FabriC 2019/09/15 19:40:00
+3 (3)
On K40 you need to deal with the NVMREG errata. Otherwise C programs don't access const data (stored in flash) properly. The errata sheet has a manual method of doing this, but recent versions of XC8 can implement the fix by telling them to.
I think by adding "nvmreg" in the project properties under XC8 Linker, Errata  - the the compiler manual.

Go Navy! Beat Army!
#2
paulfjujo
paulfjujo
  • Total Posts : 72
  • Reward points : 0
  • Joined: 2011/03/08 05:33:46
  • Location: France 01700
  • Status: offline
Re: EUSART sending null characters 2019/07/26 11:48:23 (permalink)
-1 (1)
hello,
 
you better have to use
char *txt; // define a char pointer
char TEXTE[]="Hello world"; // define an area to store your message
 
txt=&TEXTE[0];



then use this pointer

 
 
 
eusart2_prints(txt);
 
 
 

post edited by paulfjujo - 2019/07/26 11:51:47
#3
1and0
Access is Denied
  • Total Posts : 9771
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: EUSART sending null characters 2019/07/26 12:23:44 (permalink)
+2 (2)
paulfjujo
you better have to use
char *txt; // define a char pointer
char TEXTE[]="Hello world"; // define an area to store your message
 
txt=&TEXTE[0];


That is NOT better, as now you have two arrays -- one in ROM and one in RAM -- wasting resources.
 
Anyway, as mentioned, OP's problem is the NVMREG errata.
#4
jtemples
عُضْوٌ جَدِيد
  • Total Posts : 11347
  • Reward points : 0
  • Joined: 2004/02/13 12:31:19
  • Location: Southern California
  • Status: offline
Re: EUSART sending null characters 2019/07/26 14:10:18 (permalink)
+1 (1)
you better have to use

 
How does adding more code make it better?
#5
FabriC
New Member
  • Total Posts : 2
  • Reward points : 0
  • Joined: 2019/05/24 20:06:54
  • Location: 0
  • Status: offline
Re: EUSART sending null characters 2019/09/15 19:41:56 (permalink)
0
I know it's been a while since you answered this but I just wanted to thank you for your answer. It worked and until now I didn't know anything about the ERRATA sheet, so thanks.
#6
Jump to:
© 2019 APG vNext Commercial Version 4.5