lpcware

UART3 and CMSIS

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by Homayon on Sun Jun 08 08:14:22 MST 2014
I wrote a program to launch UART3 with CMSIS but does not work.
But UART0, 1 do they do.
In your opinion, where is my problem?


#include <lpc17xx.h>
#include <string.h>
#include <ctype.h>
#include "LPC17xx_pinsel.h"
#include "LPC17xx_uart.h"
#include "debug_frmwrk.h"

char Buffer0[500];
char Buffer1[500];
char Buffer3[500];
char lcd[20];
uint8_t input0;
uint8_t input1;
uint8_t input3;

void upper(char Buf[],int LeN){// tabe tabdel horofef kochaak be bozorg
for(LeN=0;LeN<501;LeN++){
Buf[LeN]=toupper(Buf[LeN]);
}
}

void C_buf(char Buf[]){// Empty Buffer
int LeN;
LeN=strlen(Buf);
for(LeN=0;LeN<501;LeN++){
Buf[LeN]=0;
}
}
//************************************************************************
void UART0_IRQHandler(void)
{
int A;
input0 = UART_ReceiveByte(LPC_UART0);
if(input0>0x20 & input0<0x7f){
A=strlen(Buffer0);
  Buffer0[A]=input0;
upper(Buffer0,500);
  UARTPuts_(LPC_UART0,Buffer0);
//UARTPuts_(LPC_UART0,"HOMAYON");
}
}
//************************************************************************
void UART1_IRQHandler(void)
{
int A;
input1 = UART_ReceiveByte((LPC_UART_TypeDef*)LPC_UART1);
if(input1>0x20 & input1<0x7f){
A=strlen(Buffer1);
  Buffer1[A]=input1;
upper(Buffer1,500);

  UARTPuts_(LPC_UART0,Buffer1);
//UARTPuts_((LPC_UART_TypeDef *)LPC_UART1, Buffer1);
}
}
//************************************************************************
void UART3_IRQHandler(void)
{
int A;
input3 = UART_ReceiveByte(LPC_UART3);
if(input3>0x20 & input3<0x7f){
A=strlen(Buffer3);
  Buffer3[A]=input3;
upper(Buffer3,500);

  UARTPuts_(LPC_UART3,Buffer3);
//UARTPuts_((LPC_UART_TypeDef *)LPC_UART1, Buffer1);
}
}

int main(void){
int len;
UART_CFG_Type UART_InitStruct;
UART_FIFO_CFG_Type UARTFIFOConfigStruct;
PINSEL_CFG_Type PinCfg;
uint32_t CLKPWR_PCONP_PCUART3;
debug_frmwrk_init();
//-------------------------    UART0   -----------------------------------------------------------

UARTFIFOConfigStruct.FIFO_DMAMode = DISABLE;
UARTFIFOConfigStruct.FIFO_Level = UART_FIFO_TRGLEV0;
UARTFIFOConfigStruct.FIFO_ResetRxBuf = ENABLE;
UARTFIFOConfigStruct.FIFO_ResetTxBuf = ENABLE;

UART_FIFOConfig(LPC_UART0, &UARTFIFOConfigStruct);
UART_IntConfig(LPC_UART0, UART_INTCFG_RBR, ENABLE);

NVIC_EnableIRQ(UART0_IRQn);
UART_TxCmd(LPC_UART0,ENABLE);

//-------------------------    UART1   -----------------------------------------------------------

PinCfg.Portnum=2;
PinCfg.Pinnum=0;
PinCfg.Funcnum=2;
PinCfg.OpenDrain=0;
PinCfg.Pinmode=0;
PINSEL_ConfigPin(&PinCfg);//TXD1
PinCfg.Pinnum=1;
PINSEL_ConfigPin(&PinCfg);//RXD1


UART_InitStruct.Baud_rate=9600;
UART_InitStruct.Databits = UART_DATABIT_8;
UART_InitStruct.Parity = UART_PARITY_NONE;
UART_InitStruct.Stopbits = UART_STOPBIT_1;


UART_Init((LPC_UART_TypeDef *)LPC_UART1, &UART_InitStruct);
UART_FIFOConfig((LPC_UART_TypeDef *)LPC_UART1, &UARTFIFOConfigStruct);
UART_IntConfig((LPC_UART_TypeDef *)LPC_UART1, UART_INTCFG_RBR, ENABLE);

NVIC_EnableIRQ(UART1_IRQn);
UART_TxCmd((LPC_UART_TypeDef *)LPC_UART1, ENABLE);

//-------------------------    UART3   -----------------------------------------------------------

CLKPWR_ConfigPPWR(CLKPWR_PCONP_PCUART3,ENABLE);
PinCfg.Portnum=4;
PinCfg.Pinnum=28;
PinCfg.Funcnum=3;
PinCfg.OpenDrain=0;
PinCfg.Pinmode=0;
PINSEL_ConfigPin(&PinCfg);//TXD3
PinCfg.Pinnum=29;
PINSEL_ConfigPin(&PinCfg);//RXD3

UART_InitStruct.Baud_rate=115200;
UART_InitStruct.Databits = UART_DATABIT_8;
UART_InitStruct.Parity = UART_PARITY_NONE;
UART_InitStruct.Stopbits = UART_STOPBIT_1;


UART_Init(LPC_UART3, &UART_InitStruct);
UART_FIFOConfig(LPC_UART3, &UARTFIFOConfigStruct);
UART_IntConfig(LPC_UART3, UART_INTCFG_RBR, ENABLE);


NVIC_EnableIRQ(UART3_IRQn);
UART_TxCmd(LPC_UART3, ENABLE);

//---------------------------------------------------------------------------------------------


while(1){
UARTPuts_(LPC_UART3,"HOMAYON");
UART_Send(LPC_UART3,"HOMAYON",7,BLOCKING);
len=strlen(Buffer0);
if(len>200){
C_buf(Buffer0);
}

}
}

Original Attachment has been moved to: RS485%20%5B1%5D.rar

Outcomes