LPC1768

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

LPC1768

1,195 Views
ssr123
Contributor I
Hello, I am new to LPC Microcontrollers and I want to write '1' to a particular Pin on LPC1768 that performs the function of SCK(Serial Clock). My question is, Do I need to always use PINSEL to select the pin before I use FIODIR and set the Pin. Also what are difference between the statements below: LPC_PINCON->FIODIR |= (1<<15); LPC_GPIO0->FIODIR |= (1<<15); LPC_GPIO0->FIODIR |= ((1<<15) | (1<<16)); LPC_GPIO2->FIODIR &= ~((1<<15) | (1<<16)); Thank you.
0 Kudos
Reply
1 Reply

1,186 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

I think the line LPC_PINCON->FIODIR |= (1<<15); is incorrect.

The line LPC_GPIO0->FIODIR |= (1<<15); is correct, in other words, the FIODIR  register is only belongs to GPIO module rather than IOCON.

For IOCON module, pls use the PINSEL[reg] to select the pin function.

 

void Chip_IOCON_PinMuxSet(LPC_IOCON_T *pIOCON, uint8_t port, uint8_t pin, uint32_t modefunc)
{
Chip_IOCON_PinMux(pIOCON, port, pin,
/* mode is in bits 3:2 */
modefunc >> 2,
/* func is in bits 1:0 */
modefunc & 3 );
}

/* Setup pin modes and function */
void Chip_IOCON_PinMux(LPC_IOCON_T *pIOCON, uint8_t port, uint8_t pin, uint32_t mode, uint8_t func)
{
uint8_t reg, bitPos;
uint32_t temp;

bitPos = IOCON_BIT_INDEX(pin);
reg = IOCON_REG_INDEX(port,pin);

temp = pIOCON->PINSEL[reg] & ~(0x03UL << bitPos);
pIOCON->PINSEL[reg] = temp | (func << bitPos);

temp = pIOCON->PINMODE[reg] & ~(0x03UL << bitPos);
pIOCON->PINMODE[reg] = temp | (mode << bitPos);
}

 

Pin mux block:

xiangjun_rong_0-1619593997486.png

Hope it can help you

BR

Xiangjun Rong

 

0 Kudos
Reply