Page 1 of 1

How to change the N76E003 HIRC frequency for more accurate UART transmission?

Posted: 28 Mar 2017, 10:39
by a_ziliu
The N76E003 HIRC frequency is 16 MHz and the deviation is less than 1% at room temperature. When using the baud rate up to 38400 for UArT transmission, 16 MHz cannot be divided by 38400 Hz, such that baud rate deviation is too large and the transmission cannot be stabilized.
At this time, user can change the HIRC frequency to 16.588 MHz to produce an accurate baud rate.

The steps of changing the HIRC frequency are as follows:
Trim value = RCTRIM0(HIRCTRIM[8:1]) + RCTRIM1(HIRCTRIM[0])
Adjust the HIRC frequency to 16.6 MHz;
Write the calculated value back to RCTRIM0 and RCTRIM1, and the HIRC change will take effect immediately after writing;
The HIRC will revert to 16 MHz after each power-up, and the user needs to change the HIRC by writing the SFR.
Recalculate the baud rate based on 16.588 MHz and set the baud rate generated by the timer to meet the standard baud rate.

Example samples:
sfr RCTRIM0 = 0x84;
sfr RCTRIM1 = 0x85;
bit BIT_TMP;

#define set_IAPEN BIT_TMP = EA; EA=0; TA=0xAA; TA=0x55; CHPCON |= SET_BIT0; EA= BIT_TMP
#define set_IAPGO BIT_TMP = EA; EA = 0; TA = 0xAA; TA = 0x55; IAPTRG |= SET_BIT0; EA = BIT_TMP
#define clr_IAPEN BIT_TMP = EA; EA = 0; TA = 0xAA; TA = 0x55; CHPCON &= ~SET_BIT0; EA=BIT_TMP

unsigned char hircmap0,hircmap1;
unsigned int trimvalue16bit;

void MODIFY_HIRC_VLAUE(void)
{
set_IAPEN;
IAPAL = 0x30;
IAPAH = 0x00;
IAPCN = READ_UID;
set_IAPGO;
hircmap0 = IAPFD;
IAPAL = 0x31;
IAPAH = 0x00;
set_IAPGO;
hircmap1 = IAPFD;
clr_IAPEN;
trimvalue16bit = ((hircmap0<<1)+(hircmap1&0x01));
trimvalue16bit = trimvalue16bit - 15;
hircmap1 = trimvalue16bit&0x01;
hircmap0 = trimvalue16bit>>1;
TA=0XAA;
TA=0X55;
RCTRIM0 = hircmap0;
TA=0XAA;
TA=0X55;
RCTRIM1 = hircmap1;
}