Issues with HardFault_Handler in uart0

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Issues with HardFault_Handler in uart0

286 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by hmd on Mon Oct 31 12:53:50 MST 2011
Hi all,
I made an uart driver, workig fine as an standalone project on an lpcxpresso 1769.
When i include the uart files with a project using several other peripherals (spi, timers,...) the project compiles fine.
When i load the programme, it doesnt work. start debbuging and it fails when ever it goes to uart initialisation,  specially when i select the pin function (before or after setting the uart peripheral!).
initialisation function:

void InitUart0 (void){
    //Power Control for Peripherals register: PCONP
    PCONP |= 1 << 3;                            // UART0 power/clock control bit.

    //activation du peripherique: PCLKSEL0      
    PCLKSEL0 |= (1 << 6); // PCLK_peripheral = CCLK

    //configuration des registres de l'uart
    U0LCR |= 1 << 7;                            // DLAB = 1
    U0LCR |= ( 1 << 0 | 1 << 1 );          // 8-bit character length

    //UART0 Baud Rate  : 19200

    U0DLL = 13;              
    U0DLM = 0;               

    // utilisation de la FIFO
    U0FCR |= (1 << 1 | 1 << 2);              // Clear FIFOs Tx/Rx  > self clear bit
    U0FCR |= 1 << 0;                             // enable FIFOs

    //enabling the interrupt
//    U0IER = 3;                // enable RBR(Receive Data Available) and THRE

    //Selection mode uart en sortie: pins P0.2 et P0.3
[B]    PinSelReg->PinSel0.Bitfield.P0_2 = 1;         // selected TXD0
    PinSelReg->PinSel0.Bitfield.P0_3 = 1;        // selected RXD0
[/B]
    //fin de configuration des registres de l'uart                         
    U0LCR = 3;                      // DLAB = 0
}
 
When ever i reach the bold lines the system goes to HardFault_Handler!!!
I made another project just spi and uart: same result. My uart project works fine.
For info: uart initialisation start first after the main or after other peripheral init is the same result... I spend all the afternoon looking around :confused:
I'm open to all suggestion.

thanks for your help.
0 Kudos
2 Replies

248 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by hmd on Mon Oct 31 15:10:19 MST 2011
Thanks Zero for your quick answer,
#3 worked  directly using PINSEL0 as you specified. this register is R/W it was working so far with bitfields acces.
#2 PCONP is allways enabled for uart0. i will chek IOCON
#1 I hoped to modify my post before any answer. too late i'm using LPCxpresso 1769.

Thanks again.
0 Kudos

248 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Mon Oct 31 13:17:07 MST 2011
#1 Could be helpful if you tell us which LPC you are using

#2 Use your debugger to check again your PCONP of UART and IOCON (bit 15 at LPC17xx) just before HardFault appears :eek:

#3 Use a standard Pinsel0 setup like:
[INDENT]
// Set PINSEL0 P0.2 = TXD0, P0.3 = RXD0
LPC_PINCON->PINSEL0 &= ~0xf0;
LPC_PINCON->PINSEL0 |= ((1 << 4) | (1 << 6));
[/INDENT]
0 Kudos