cancel
Showing results for 
Search instead for 
Did you mean: 

no receive on UART0 when CAN used

craig239955_st
Associate II
Posted on June 07, 2007 at 04:52

no receive on UART0 when CAN used

3 REPLIES 3
craig239955_st
Associate II
Posted on May 17, 2011 at 09:42

In my application I use UART0 and the CAN interface.

UART0 RxD = P3.0 (Alternate Input 1)

UART0 TxD = P3.4 (Alternate Output 3)

CAN RxD = P5.0 (Alternate Input 1)

CAN TxD = P5.1 (Alternate Output 2)

When I init the CAN interface I am unable to receive characters from the serial port.

The problem is solved when I disconnect the InputPin from port 5.1.

Following functions are used to init UART0 and CAN.

Code:

void INIT_CAN(void) {

GPIO_InitTypeDef GPIOInit;

SCU_APBPeriphReset(__CAN,DISABLE);

SCU_APBPeriphReset(__GPIO5,DISABLE);

SCU_APBPeriphClockConfig(__GPIO5,ENABLE);

SCU_APBPeriphClockConfig(__CAN,ENABLE);

//Port 5.0 CAN Rx

GPIO_StructInit(&GPIOInit);

GPIOInit.GPIO_Pin = GPIO_Pin_0;

GPIOInit.GPIO_Direction = GPIO_PinInput;

GPIOInit.GPIO_Type = GPIO_Type_PushPull;

GPIOInit.GPIO_IPConnected = GPIO_IPConnected_Enable;

GPIOInit.GPIO_Alternate = GPIO_InputAlt1;

GPIO_Init(GPIO5,&GPIOInit);

//Port 5.1 CAN Tx

GPIO_StructInit(&GPIOInit);

GPIOInit.GPIO_Pin = GPIO_Pin_1;

GPIOInit.GPIO_Direction = GPIO_PinOutput;

GPIOInit.GPIO_Type = GPIO_Type_PushPull;

GPIOInit.GPIO_IPConnected = GPIO_IPConnected_Enable; //<== MUST BE GPIO_IPConnected_Disable WHY ???????

GPIOInit.GPIO_Alternate = GPIO_OutputAlt2;

GPIO_Init(GPIO5,&GPIOInit);

}

void INIT_UARTS(void) {

GPIO_InitTypeDef GPIOInit;

SCU_APBPeriphReset(__UART0,DISABLE);

SCU_APBPeriphReset(__UART1,DISABLE);

SCU_APBPeriphReset(__UART2,DISABLE);

SCU_APBPeriphReset(__GPIO3,DISABLE);

SCU_APBPeriphClockConfig(__UART0,ENABLE); //STS0

SCU_APBPeriphClockConfig(__UART1,ENABLE); //STS1

SCU_APBPeriphClockConfig(__UART2,ENABLE); //STS2 (modbus)

SCU_APBPeriphClockConfig(__GPIO3,ENABLE);

//RxD0, RxD2, RxD1

GPIOInit.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2;

GPIOInit.GPIO_Direction = GPIO_PinInput;

GPIOInit.GPIO_Type = GPIO_Type_PushPull;

GPIOInit.GPIO_IPConnected = GPIO_IPConnected_Enable;

GPIOInit.GPIO_Alternate = GPIO_InputAlt1;

GPIO_Init(GPIO3,&GPIOInit);

//TxD1

GPIOInit.GPIO_Pin = GPIO_Pin_3;

GPIOInit.GPIO_Direction = GPIO_PinOutput;

GPIOInit.GPIO_Alternate = GPIO_OutputAlt2;

GPIO_Init(GPIO3,&GPIOInit);

//TxD0, TxD2

GPIOInit.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5;

GPIOInit.GPIO_Direction = GPIO_PinOutput;

GPIOInit.GPIO_Alternate = GPIO_OutputAlt3;

GPIO_Init(GPIO3,&GPIOInit);

}

Kind regards

Luc

truf9
Associate II
Posted on May 17, 2011 at 09:42

Hello Luc,

I have the same problem now. Do you find out, when to enable or disable the IP-Connect???

Thomas

craig239955_st
Associate II
Posted on May 17, 2011 at 09:42

Hi,

When the input of UART Tx is connected, the CAN interface does not transmit in normal mode. In loopbackmode (Non Silent), it works OK.

Same thing for the UART. When CAN is assigned on P5 and UART on P3, and IP is connected, the UART cannot receive.

I don't know if this problem occures when using other pins on other ports.

The workaround is to disconnect the inputs at Tx.

I searched days to find this out ... so maybe this can be interresting for others ...

Here is the initialisation code :

Code:

void CAN_INIT(void) {

SCU_APBPeriphReset(__CAN,DISABLE);

SCU_APBPeriphReset(__GPIO5,DISABLE);

SCU_APBPeriphClockConfig(__GPIO5,ENABLE);

SCU_APBPeriphClockConfig(__CAN,ENABLE);

GPIO_InitTypeDef GPIOInit;

//Port 5.0 CAN Rx

GPIO_StructInit(&GPIOInit);

GPIOInit.GPIO_Pin = GPIO_Pin_0;

GPIOInit.GPIO_Direction = GPIO_PinInput;

GPIOInit.GPIO_Type = GPIO_Type_PushPull;

GPIOInit.GPIO_IPConnected = GPIO_IPConnected_Enable;

GPIOInit.GPIO_Alternate = GPIO_InputAlt1;

GPIO_Init(GPIO5,&GPIOInit);

//Port 5.1 CAN Tx

GPIO_StructInit(&GPIOInit);

GPIOInit.GPIO_Pin = GPIO_Pin_1;

GPIOInit.GPIO_Direction = GPIO_PinOutput;

GPIOInit.GPIO_Type = GPIO_Type_PushPull;

GPIOInit.GPIO_IPConnected = GPIO_IPConnected_Enable;

GPIOInit.GPIO_Alternate = GPIO_OutputAlt2;

GPIO_Init(GPIO5,&GPIOInit);

}

void UART_INIT(void) {

GPIO_InitTypeDef GPIOInit;

SCU_APBPeriphReset(__UART0,DISABLE);

SCU_APBPeriphReset(__UART1,DISABLE);

SCU_APBPeriphReset(__UART2,DISABLE);

SCU_APBPeriphReset(__GPIO3,DISABLE);

SCU_APBPeriphClockConfig(__UART0,ENABLE);

SCU_APBPeriphClockConfig(__UART1,ENABLE);

SCU_APBPeriphClockConfig(__UART2,ENABLE);

SCU_APBPeriphClockConfig(__GPIO3,ENABLE);

//RxD0, RxD2, RxD1

GPIOInit.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2;

GPIOInit.GPIO_Direction = GPIO_PinInput;

GPIOInit.GPIO_Type = GPIO_Type_PushPull;

GPIOInit.GPIO_IPConnected = GPIO_IPConnected_Enable;

GPIOInit.GPIO_Alternate = GPIO_InputAlt1;

GPIO_Init(GPIO3,&GPIOInit);

//TxD1

GPIOInit.GPIO_Pin = GPIO_Pin_3;

GPIOInit.GPIO_IPConnected = GPIO_IPConnected_Disable; //<<<GPIO_IPConnected_Enable does not work !!!

GPIOInit.GPIO_Direction = GPIO_PinOutput;

GPIOInit.GPIO_Alternate = GPIO_OutputAlt2;

GPIO_Init(GPIO3,&GPIOInit);

//TxD0, TxD2

GPIOInit.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5;

GPIOInit.GPIO_Direction = GPIO_PinOutput;

GPIOInit.GPIO_Alternate = GPIO_OutputAlt3;

GPIO_Init(GPIO3,&GPIOInit);

}