Dear,
I am working with a custom board with LPC55S28. In this board I am using 4 flexcomm as USART and some works and some no and I don't understand why! The configuration is the same for all. The code is the following:
#define UART_LTE_PERIPHERAL ((USART_Type *)FLEXCOMM0)
//#define UART_LTE_CLOCK kPLL0_DIV_to_FLEXCOMM0
#define UART_LTE_CLOCK kFRO_HF_DIV_to_FLEXCOMM0
#define UART_LTE_PERIPHERAL_RESET kFC0_RST_SHIFT_RSTn
#define UART_LTE_CLOCK_FREQUENCY CLOCK_GetFlexCommClkFreq(0U)
#define UART_LTE_BAUDRATE (115200ul)
#define UART_LTE_IRQ FLEXCOMM0_IRQn
#define UART_LTE_IRQ_HANDLER FLEXCOMM0_IRQHandler
#define UART_LTE_TX_GPIO GPIO
#define UART_LTE_TX_PORT 0U
#define UART_LTE_TX_PIN 30U
#define UART_LTE_TX_ALT_FUNC 0x01u
#define UART_LTE_RX_GPIO GPIO
#define UART_LTE_RX_PORT 0U
#define UART_LTE_RX_PIN 29U
#define UART_LTE_RX_ALT_FUNC 0x01u
#define UART_BLUETOOTH_PERIPHERAL ((USART_Type *)FLEXCOMM7)
#define UART_BLUETOOTH_CLOCK kFRO_HF_DIV_to_FLEXCOMM7
#define UART_BLUETOOTH_PERIPHERAL_RESET kFC7_RST_SHIFT_RSTn
#define UART_BLUETOOTH_CLOCK_FREQUENCY CLOCK_GetFlexCommClkFreq(7U)
#define UART_BLUETOOTH_BAUDRATE (115200ul)
#define UART_BLUETOOTH_IRQ FLEXCOMM7_IRQn
#define UART_BLUETOOTH_IRQ_HANDLER FLEXCOMM7_IRQHandler
#define UART_BLUETOOTH_TX_GPIO GPIO
#define UART_BLUETOOTH_TX_PORT 0U
#define UART_BLUETOOTH_TX_PIN 19U
#define UART_BLUETOOTH_TX_ALT_FUNC 0x07u
#define UART_BLUETOOTH_RX_GPIO GPIO
#define UART_BLUETOOTH_RX_PORT 1U
#define UART_BLUETOOTH_RX_PIN 29U
#define UART_BLUETOOTH_RX_ALT_FUNC 0x01u
// Modbus #1
#define RS485_1_PERIPHERAL ((USART_Type *)FLEXCOMM1)
#define RS485_1_CLOCK kFRO_HF_DIV_to_FLEXCOMM1
#define RS485_1_PERIPHERAL_RESET kFC1_RST_SHIFT_RSTn
#define RS485_1_CLOCK_FREQUENCY CLOCK_GetFlexCommClkFreq(1U)
#define RS485_1_BAUDRATE (115200ul)
#define RS485_1_IRQ FLEXCOMM1_IRQn
#define RS485_1_IRQ_HANDLER FLEXCOMM1_IRQHandler
#define RS485_1_TX_GPIO GPIO
#define RS485_1_TX_PORT 0U
#define RS485_1_TX_PIN 14U
#define RS485_1_TX_ALT_FUNC 0x06u
#define RS485_1_RX_GPIO GPIO
#define RS485_1_RX_PORT 0U
#define RS485_1_RX_PIN 13U
#define RS485_1_RX_ALT_FUNC 0x05u
// Modbus #2
#define RS485_2_PERIPHERAL ((USART_Type *)FLEXCOMM4)
#define RS485_2_CLOCK kFRO_HF_DIV_to_FLEXCOMM4
#define RS485_2_PERIPHERAL_RESET kFC4_RST_SHIFT_RSTn
#define RS485_2_CLOCK_FREQUENCY CLOCK_GetFlexCommClkFreq(4U)
#define RS485_2_BAUDRATE (115200ul)
#define RS485_2_IRQ FLEXCOMM4_IRQn
#define RS485_2_IRQ_HANDLER FLEXCOMM4_IRQHandler
#define RS485_2_TX_GPIO GPIO
#define RS485_2_TX_PORT 0U
#define RS485_2_TX_PIN 20U
#define RS485_2_TX_ALT_FUNC 0x0Bu
#define RS485_2_RX_GPIO GPIO
#define RS485_2_RX_PORT 0U
#define RS485_2_RX_PIN 5U
#define RS485_2_RX_ALT_FUNC 0x02u
static void initUART (bool exitLowPower)
{
(void)exitLowPower;
// 4G/LTE UART Management
CLOCK_AttachClk(UART_LTE_CLOCK);
RESET_ClearPeripheralReset(UART_LTE_PERIPHERAL_RESET);
uint32_t pinConfig = (
UART_LTE_TX_ALT_FUNC |
/* Selects pull-up function */
IOCON_PIO_MODE(0) |
/* Standard mode, output slew rate control is enabled */
IOCON_PIO_SLEW(0) |
/* Input function is not inverted */
IOCON_PIO_INVERT(0) |
/* Enables digital function */
IOCON_PIO_DIGIMODE(1));
IOCON_PinMuxSet(IOCON,UART_LTE_TX_PORT,UART_LTE_TX_PIN,pinConfig);
pinConfig = (
UART_LTE_RX_ALT_FUNC |
/* Selects pull-up function */
IOCON_PIO_MODE(0) |
/* Standard mode, output slew rate control is enabled */
IOCON_PIO_SLEW(0) |
/* Input function is not inverted */
IOCON_PIO_INVERT(0) |
/* Enables digital function */
IOCON_PIO_DIGIMODE(1));
IOCON_PinMuxSet(IOCON,UART_LTE_RX_PORT,UART_LTE_RX_PIN,pinConfig);
usart_config_t uartLTEConfig =
{
.baudRate_Bps = UART_LTE_BAUDRATE,
.syncMode = kUSART_SyncModeDisabled,
.parityMode = kUSART_ParityDisabled,
.stopBitCount = kUSART_OneStopBit,
.bitCountPerChar = kUSART_8BitsPerChar,
.loopback = false,
.txWatermark = kUSART_TxFifo0,
.rxWatermark = kUSART_RxFifo1,
.enableRx = true,
.enableTx = true,
.enableHardwareFlowControl = false,
.enableMode32k = false,
.clockPolarity = kUSART_RxSampleOnFallingEdge,
.enableContinuousSCLK = false
};
USART_Init(UART_LTE_PERIPHERAL,&uartLTEConfig,UART_LTE_CLOCK_FREQUENCY);
USART_EnableInterrupts(UART_LTE_PERIPHERAL, kUSART_RxLevelInterruptEnable | kUSART_RxErrorInterruptEnable);
EnableIRQ(UART_LTE_IRQ);
// BLE/DEBUG UART Management
CLOCK_AttachClk(UART_BLUETOOTH_CLOCK);
RESET_ClearPeripheralReset(UART_BLUETOOTH_PERIPHERAL_RESET);
pinConfig = (
UART_BLUETOOTH_TX_ALT_FUNC |
/* Selects pull-up function */
IOCON_PIO_MODE(0) |
/* Standard mode, output slew rate control is enabled */
IOCON_PIO_SLEW(0) |
/* Input function is not inverted */
IOCON_PIO_INVERT(0) |
/* Enables digital function */
IOCON_PIO_DIGIMODE(1));
IOCON_PinMuxSet(IOCON,UART_BLUETOOTH_TX_PORT,UART_BLUETOOTH_TX_PIN,pinConfig);
pinConfig = (
UART_BLUETOOTH_RX_ALT_FUNC |
/* Selects pull-up function */
IOCON_PIO_MODE(0) |
/* Standard mode, output slew rate control is enabled */
IOCON_PIO_SLEW(0) |
/* Input function is not inverted */
IOCON_PIO_INVERT(0) |
/* Enables digital function */
IOCON_PIO_DIGIMODE(1));
IOCON_PinMuxSet(IOCON,UART_BLUETOOTH_RX_PORT,UART_BLUETOOTH_RX_PIN,pinConfig);
usart_config_t uartBluetoothConfig =
{
.baudRate_Bps = UART_BLUETOOTH_BAUDRATE,
.syncMode = kUSART_SyncModeDisabled,
.parityMode = kUSART_ParityDisabled,
.stopBitCount = kUSART_OneStopBit,
.bitCountPerChar = kUSART_8BitsPerChar,
.loopback = false,
.txWatermark = kUSART_TxFifo0,
.rxWatermark = kUSART_RxFifo1,
.enableRx = true,
.enableTx = true,
.enableHardwareFlowControl = false,
.enableMode32k = false,
.clockPolarity = kUSART_RxSampleOnFallingEdge,
.enableContinuousSCLK = false
};
USART_Init(UART_BLUETOOTH_PERIPHERAL,&uartBluetoothConfig,UART_BLUETOOTH_CLOCK_FREQUENCY);
//FIXME: USART_EnableInterrupts(UART_BLUETOOTH_PERIPHERAL, kUSART_RxLevelInterruptEnable | kUSART_RxErrorInterruptEnable);
//FIXME: EnableIRQ(UART_BLUETOOTH_IRQ);
// Modbus #1 UART Management
CLOCK_AttachClk(RS485_1_CLOCK);
RESET_ClearPeripheralReset(RS485_1_PERIPHERAL_RESET);
pinConfig = (
RS485_1_TX_ALT_FUNC |
/* Selects pull-up function */
IOCON_PIO_MODE(0) |
/* Standard mode, output slew rate control is enabled */
IOCON_PIO_SLEW(0) |
/* Input function is not inverted */
IOCON_PIO_INVERT(0) |
/* Enables digital function */
IOCON_PIO_DIGIMODE(1));
IOCON_PinMuxSet(IOCON,RS485_1_TX_PORT,RS485_1_TX_PIN,pinConfig);
pinConfig = (
RS485_1_RX_ALT_FUNC |
/* Selects pull-up function */
IOCON_PIO_MODE(0) |
/* Standard mode, output slew rate control is enabled */
IOCON_PIO_SLEW(0) |
/* Input function is not inverted */
IOCON_PIO_INVERT(0) |
/* Enables digital function */
IOCON_PIO_DIGIMODE(1));
IOCON_PinMuxSet(IOCON,RS485_1_RX_PORT,RS485_1_RX_PIN,pinConfig);
USART_Init(RS485_1_PERIPHERAL,&uartModbus1Config,RS485_1_CLOCK_FREQUENCY);
// USART_EnableInterrupts(RS485_1_PERIPHERAL, kUSART_RxLevelInterruptEnable | kUSART_RxErrorInterruptEnable);
// EnableIRQ(RS485_1_IRQ);
// Modbus #2 UART Management
CLOCK_AttachClk(RS485_2_CLOCK);
RESET_ClearPeripheralReset(RS485_2_PERIPHERAL_RESET);
pinConfig = (
RS485_2_TX_ALT_FUNC |
/* Selects pull-up function */
IOCON_PIO_MODE(0) |
/* Standard mode, output slew rate control is enabled */
IOCON_PIO_SLEW(0) |
/* Input function is not inverted */
IOCON_PIO_INVERT(0) |
/* Enables digital function */
IOCON_PIO_DIGIMODE(1));
IOCON_PinMuxSet(IOCON,RS485_2_TX_PORT,RS485_2_TX_PIN,pinConfig);
pinConfig = (
RS485_2_RX_ALT_FUNC |
/* Selects pull-up function */
IOCON_PIO_MODE(0) |
/* Standard mode, output slew rate control is enabled */
IOCON_PIO_SLEW(0) |
/* Input function is not inverted */
IOCON_PIO_INVERT(0) |
/* Enables digital function */
IOCON_PIO_DIGIMODE(1));
IOCON_PinMuxSet(IOCON,RS485_2_RX_PORT,RS485_2_RX_PIN,pinConfig);
USART_Init(RS485_2_PERIPHERAL,&uartModbus2Config,RS485_2_CLOCK_FREQUENCY);
// USART_EnableInterrupts(RS485_2_PERIPHERAL, kUSART_RxLevelInterruptEnable | kUSART_RxErrorInterruptEnable);
// EnableIRQ(RS485_2_IRQ);
}
The RS485_2 (flexcomm4) and LTE (flexcomm0) works and I can transmit data. The other two doens't works and the tx line is always low. I check the pin and the configuration several times... can you help me to find the bug?
Best
Marco
Hi,
First of all, you have to enable the IOCON module clock before you initialize the IOCON register, pls add the line at the first of the code.
I have checked the other code, it appears it is okay.
Hope it can help you
BR
Xiangjun Rong
CLOCK_EnableClock(kCLOCK_Iocon);
Hi @xiangjun_rong ,
thanks for your reply. In the code I put in the previous message I forgot the line to enable the IOCON, but before calling the initUarts() I enable the IOCON clock.
Any other tips?
BR
Marco
Hi,
The SDK has the example of uart in interrupt mode, pls try to run it and check if there is issue.
I suggest you have the uart to transfer char repeatedly, then check if you can receive the char or check the waveform of the uart TX pin.
Hope it can help you
BR
XiangJun Rong