Hi,
I am not getting expected output of UART4 of PIC18F67K40 MCU and my code is:
#define _XTAL_FREQ 16000000
void main()
{
//ANSELC = 0;
TRISC.B1 = 1; //rx
TRISC.B0 = 0; //tx
// remappable funciton
Unlock_IOLOCK();
//PPS_Mapping(30, _OUTPUT, _TX4_CK);
PPS_Mapping_NoLock(30, _OUTPUT, _TX4_CK4);
PPS_Mapping_NoLock(29, _INPUT, _RX4);
Lock_IOLOCK();
//UART4_Init(9600);
UART4_Remappable_Init(9600);
Delay_ms(100);
// for blinking LED
ANSELD = 0;
TRISD = 0;
LATD = 0;
while(1)
{
UART4_Remappable_Write("H \n");
Delay_ms(1000);
LATD = 0b00000000;
UART4_Remappable_Write("J \n");
Delay_ms(1000);
LATD = 0b01000000;
UART4_Remappable_Write("K \n");
Delay_ms(1000);
}
}
and one more method is:
void OSCILLATOR_Initialize(void){
OSCCON1 = 0x60;
// CSWHOLD may proceed; SOSCPWR Low power;
OSCCON3 = 0x00;
// MFOEN disabled; LFOEN disabled; ADOEN disabled; SOSCEN disabled; EXTOEN disabled; HFOEN disabled;
OSCEN = 0x00;
// HFFRQ 16_MHz;
OSCFRQ = 0x05;
// TUN 0;
OSCTUNE = 0x00;
}
void main() {
TRISD = 0x00;
LATD = 0x00;
// TRISC1_bit = 1; // Configure RE1 pin only as input // TRISC1_bit = 0;
TRISC.B1 = 1;
TRISC.B0 = 0;
OSCILLATOR_Initialize(void);
UART4_Init(115200); // Initialize UART module at 9600 bps
Delay_ms(100);
UART4_Write_Text("S");
UART4_Write(10);
UART4_Write(13);
while(1){
LATD = 0b00000000;
Delay_ms(500);
UART4_Write_Text("A");
LATD = 0b01000000;
Delay_ms(500);
UART4_Write_Text("B");
}
}
in two ways I didnt get expected output but I got output like <NULL> or some times <LF><CR>
so please tell me what were the right setting for this pic18 MCUs and where did i do mistake, please help me
Best regards
mmm
pic18f67k40 uart 4 is not working
Re: pic18f67k40 uart 4 is not working
Code: Select all
PPS_Mapping_NoLock(30, _OUTPUT, _TX4_CK4);
PPS_Mapping_NoLock(29, _INPUT, _RX4);
These are not valid options, as UART4 can only be mapped to ports B or C.
The first parameter is not the actual PIC pin number, but is encoded as described in section 17.8.2 of the datasheet.
Did you select "PPSlock can be set and cleared repeatedly" in configuration settings?
I do not own that particular PIC, so cannot verify the above. Just my understanding of the datasheet.
Start every day with a smile...... (get it over with)
Re: pic18f67k40 uart 4 is not working
Hi,
Thank for response, I new to PPS settings so I am bit confusing at
PPS_Mapping_NoLock(30, _OUTPUT, _TX4_CK4);
PPS_Mapping_NoLock(29, _INPUT, _RX4); instead of 30,29 what would be the value or number ?
And whats wrong with the second code ?
please help me.
Best regards,
mmm
Thank for response, I new to PPS settings so I am bit confusing at
PPS_Mapping_NoLock(30, _OUTPUT, _TX4_CK4);
PPS_Mapping_NoLock(29, _INPUT, _RX4); instead of 30,29 what would be the value or number ?
And whats wrong with the second code ?
please help me.
Best regards,
mmm
Re: pic18f67k40 uart 4 is not working
Default values of 0x11 for RC1 Rx, 0x12 for RC2 Tx.
Did not spot the second code - now that I see it, I cannot see obvious PPS problems, since this will just use default pins RC1, RC2.
My guess is that MCU clock speed does not match project selected speed. An oscilloscope would be the best tool to check baud rate.
A check of correct MCU clock speed can be done with a simple LED flash program of maybe 1 second on, 1 second off. You can get a rough indication just by eye.
Without owning that PIC, it is impractical for me to debug your code. I do not think I can help further.
Did not spot the second code - now that I see it, I cannot see obvious PPS problems, since this will just use default pins RC1, RC2.
My guess is that MCU clock speed does not match project selected speed. An oscilloscope would be the best tool to check baud rate.
A check of correct MCU clock speed can be done with a simple LED flash program of maybe 1 second on, 1 second off. You can get a rough indication just by eye.
Without owning that PIC, it is impractical for me to debug your code. I do not think I can help further.
Start every day with a smile...... (get it over with)
Re: pic18f67k40 uart 4 is not working
Firstly, I tried basic LED program and then I add this UART4 options, Just now I check the UART1 instead of UART4 becoz I thought UART4 is not working properly, but now I got know that that OSCCON1 and others are incorrect thats why I got wrong UART output.
And I took 64MHz clock so
I set that OSCCON1 = 0x60;
OSCCON3 = 0x00;
OSCEN = 0x00;
OSCFRQ = 0x08;
OSCTUNE = 0x00;
is there anything wrong ?
Best regards,
mmm
And I took 64MHz clock so
I set that OSCCON1 = 0x60;
OSCCON3 = 0x00;
OSCEN = 0x00;
OSCFRQ = 0x08;
OSCTUNE = 0x00;
is there anything wrong ?
Best regards,
mmm
- filip.grujcic
- Posts: 822
- Joined: 14 May 2018 08:34
Re: pic18f67k40 uart 4 is not working
Hello,
You've opened a support ticket on our helpdesk, therefore let us continue our correspondence there.
Kind regards,
You've opened a support ticket on our helpdesk, therefore let us continue our correspondence there.
Kind regards,
Filip Grujcic