2012-06-20 02:19 PM
hi.
i am using the STM32F107VC board from IAR i have some example code for CAN but in my Board they used the PD0 and PD1 for CAN i dont know how to remap it in my code. i have 2 board and i want to sent data between 2 boards.void GPIO_Configuration(void){ GPIO_InitTypeDef GPIO_InitStructure; // GPIO_PinRemapConfig(GPIO_Remap2_CAN1 , ENABLE); /* Configure CAN pin: RX */ //GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_CAN_RX; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_Init(GPIO_CAN, &GPIO_InitStructure); /* Configure CAN pin: TX */ //GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_CAN_TX; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIO_CAN, &GPIO_InitStructure); GPIO_PinRemapConfig(GPIO_Remap_CAN , ENABLE);}can any one pls help me solve this problem..thanks...2012-06-21 04:25 PM
Thanks..
i will check it from my university in morning.thanks for your help.../* Configures LED 1..4 */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4);af for configuration for my project it use PD.07, PD.13, PF.03 and PD.04 pinsbut i need to chage it to PC.06, PC.07, PC.08 and PC.09 pins according to my board how it can be done?2012-06-21 04:29 PM
af for configuration for my project it use PD.07, PD.13, PF.03 and PD.04 pins
but i need to chage it to PC.06, PC.07, PC.08 and PC.09 pins according to my board
STM32F10x_StdPeriph_Lib_V3.5.0\Utilities\STM32_EVAL\STM3210C_EVAL\stm3210c_eval.h /** @addtogroup STM3210C_EVAL_LOW_LEVEL_LED * @{ */ #define LEDn 4 #define LED1_PIN GPIO_Pin_7 #define LED1_GPIO_PORT GPIOD #define LED1_GPIO_CLK RCC_APB2Periph_GPIOD ....
2012-06-21 06:05 PM
Thanks..
atlest i did this for now...2012-06-24 04:24 PM
Hi,
Thanks for all help here...finely i got some example code for my board in IAR Workbench and it work fine... i think the message structure is some problem i guess...My advice for beginner is to check first with the right example given by the board first....then you can upgrade it to your need....i try with some other example but later on i found the right one.....if i did so i have not wasted 3 days for thisthanks again....2012-06-24 10:47 PM
if i did so i have not wasted 3 days for this
We are a sum of our experiences. ''The road of life twists and turns and no two directions are ever the same. Yet our lessons come from the journey, not the destination.�? Don Williams, Jr. (American Novelist and Poet, b.1968)
2012-06-25 09:55 AM
@clive1 thanks for your help all time...
i am just confused in some part. The code below work for the one board when i connect CAN1 & CAN2. Now i want to connect 2 board together and make communication using CAN. how i can do that?.... just i want to send data from one board and other board shouldreceiveit.... so what should i do for it?u32 CAN_Config(void)
{
CAN_InitTypeDef CAN_InitStruct;
GPIO_InitTypeDef GPIO_InitStructure;
CAN_FilterInitTypeDef CAN_FilterInitStructure;
// CAN init
// Enable GPIOD clock
RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOD | RCC_APB2Periph_AFIO, DISABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOD | RCC_APB2Periph_AFIO, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN2,ENABLE);
// Configure PD1 as CAN TX
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
// Configure PD0 as CAN RX
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
// Configure PB6 as CAN TX
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
// Configure PB5 as CAN RX
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
AFIO->MAPR |= (1ul<<
22
) | (3ul<<13);
CAN_DeInit(CAN1);
CAN_DeInit(CAN2);
/*
CAN_ITConfig( CAN_IT_TME | CAN_IT_FMP0
| CAN_IT_FF0 | CAN_IT_FOV0
| CAN_IT_FMP1 | CAN_IT_FF1
| CAN_IT_FOV1 | CAN_IT_EWG
| CAN_IT_EPV | CAN_IT_LEC | CAN_IT_BOF
| CAN_IT_ERR | CAN_IT_WKU | CAN_IT_SLK,
DISABLE);
*/
CAN_InitStruct.CAN_TTCM
=
DISABLE
;
CAN_InitStruct.CAN_ABOM
=
DISABLE
;
CAN_InitStruct.CAN_AWUM
=
DISABLE
;
CAN_InitStruct.CAN_NART
=
ENABLE
;
CAN_InitStruct.CAN_RFLM
=
ENABLE
;
CAN_InitStruct.CAN_TXFP
=
ENABLE
;
CAN_InitStruct.CAN_Mode
=
CAN_Mode_Normal
;
CAN_InitStruct.CAN_SJW
=
CAN_SJW_3tq
;
CAN_InitStruct.CAN_BS1
=
CAN_BS1_6tq
;
CAN_InitStruct.CAN_BS2
=
CAN_BS2_5tq
;
CAN_InitStruct.CAN_Prescaler
=
3
;
if(CAN_Init(CAN2,&CAN_InitStruct) == CANINITFAILED)
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN2,DISABLE);
return(0);
}
if(CAN_Init(CAN1,&CAN_InitStruct) == CANINITFAILED)
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1,DISABLE);
return(0);
}
CAN_FilterInitStructure.CAN_FilterMode
=
CAN_FilterMode_IdMask
;
CAN_FilterInitStructure.CAN_FilterScale
=
CAN_FilterScale_16bit
;
CAN_FilterInitStructure.CAN_FilterIdHigh
=
0
;
CAN_FilterInitStructure.CAN_FilterIdLow
=
0
;
CAN_FilterInitStructure.CAN_FilterMaskIdHigh
=
0
;
CAN_FilterInitStructure.CAN_FilterMaskIdLow
=
0
;
CAN_FilterInitStructure.CAN_FilterFIFOAssignment
=
CAN_FilterFIFO0
;
CAN_FilterInitStructure.CAN_FilterActivation
=
DISABLE
;
for(u32
i
=
0
; i < 14; ++i)
{
CAN_FilterInitStructure.CAN_FilterNumber
= i;
CAN_FilterInit(&CAN_FilterInitStructure);
}
return(1);
}
//---------------------------------------------------------------------------------------
void Init_RxMes(CanRxMsg *RxMessage)
{
u8
i
=
0
;
RxMessage->StdId = 0x00;
RxMessage->ExtId = 0x00;
RxMessage->IDE = CAN_ID_STD;
RxMessage->DLC = 0;
RxMessage->FMI = 0;
for (i = 0;i <
8
;i++)
RxMessage->Data[i] = 0x00;
}
//-----------------------------------------------------------------------------------
CanTxMsg CanTxMsg1;
CanRxMsg CanRxMsg1;
u32 R;
///------- Test CAN ------------------------------------------------------
u32 TestCAN(u32 Repeat)
{
CAN_FilterInitTypeDef CAN_FilterInitStructure;
CanTxMsg CanTxMsg;
CanRxMsg CanRxMsg;
u32 TO;
CAN1->FMR |= 1;
CAN1->FMR = 2<<
8
;
CAN_FilterInitStructure.CAN_FilterMode
=
CAN_FilterMode_IdList
;
CAN_FilterInitStructure.CAN_FilterScale
=
CAN_FilterScale_16bit
;
CAN_FilterInitStructure.CAN_FilterIdHigh
=
0x4440
;
CAN_FilterInitStructure.CAN_FilterIdLow
=
0x4440
;
CAN_FilterInitStructure.CAN_FilterMaskIdHigh
=
0
;
CAN_FilterInitStructure.CAN_FilterMaskIdLow
=
0
;
CAN_FilterInitStructure.CAN_FilterFIFOAssignment
=
CAN_FilterFIFO0
;
CAN_FilterInitStructure.CAN_FilterActivation
=
ENABLE
;
CAN_FilterInitStructure.CAN_FilterNumber
=
0
;
CAN_FilterInit(&CAN_FilterInitStructure);
CAN_FilterInitStructure.CAN_FilterNumber
=
2
;
CAN_FilterInit(&CAN_FilterInitStructure);
CAN_FilterInitStructure.CAN_FilterIdHigh
=
0x2220
;
CAN_FilterInitStructure.CAN_FilterIdLow
=
0x2220
;
CAN_FilterInitStructure.CAN_FilterFIFOAssignment
=
CAN_FilterFIFO1
;
CAN_FilterInitStructure.CAN_FilterNumber
=
1
;
CAN_FilterInit(&CAN_FilterInitStructure);
CAN_FilterInitStructure.CAN_FilterNumber
=
3
;
CAN_FilterInit(&CAN_FilterInitStructure);
Repeat<<=1;
for(;Repeat;Repeat--)
{
CanTxMsg.ExtId
=
0x000
;
CanTxMsg.IDE
=
DISABLE
;
CanTxMsg.RTR
=
DISABLE
;
CanTxMsg.DLC
=
8
;
CanTxMsg.StdId
=
0x111
;
CanTxMsg.Data[0] = 0x11 ^ (Repeat & 0xFF);
CanTxMsg.Data[1] = 0x22 ^ ((Repeat >> 8 ) & 0xFF);
CanTxMsg.Data[2] = 0x33 ^ ((Repeat >> 16) & 0xFF);
CanTxMsg.Data[3] = 0x44 ^ ((Repeat >> 24) & 0xFF);
CanTxMsg.Data[4] = 0x55 ^ (Repeat & 0xFF);
CanTxMsg.Data[5] = 0x66 ^ ((Repeat >> 8 ) & 0xFF);
CanTxMsg.Data[6] = 0x77 ^ ((Repeat >> 16) & 0xFF);
CanTxMsg.Data[7] = 0x88 ^ ((Repeat >> 24) & 0xFF);
CAN_Transmit(CAN1,&CanTxMsg);
// CAN1 ----> CAN2
TO = 1000;
while(!CAN_MessagePending(CAN2,1) && (--TO));
if(!TO)
{
R = Repeat;
CanTxMsg1 = CanTxMsg; CanRxMsg1 = CanRxMsg;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1,DISABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN2,DISABLE);
return(0);
}
CAN_Receive(CAN2,1,&CanRxMsg);
for(int i = 0; i <
CanRxMsg.DLC
; i++)
{
if(CanTxMsg.Data[i] != CanRxMsg.Data[i])
{
CanTxMsg1
= CanTxMsg;
CanRxMsg1
= CanRxMsg;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1,DISABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN2,DISABLE);
return(0);
}
LED_Display_All(CanRxMsg.Data[i] & 7);
}
--Repeat;
CanTxMsg.ExtId
=
0x000
;
CanTxMsg.IDE
=
DISABLE
;
CanTxMsg.RTR
=
DISABLE
;
CanTxMsg.DLC
=
8
;
CanTxMsg.StdId
=
0x111
;
CanTxMsg.Data[0] = 0x11 ^ (Repeat & 0xFF);
CanTxMsg.Data[1] = 0x22 ^ ((Repeat >> 8 ) & 0xFF);
CanTxMsg.Data[2] = 0x33 ^ ((Repeat >> 16) & 0xFF);
CanTxMsg.Data[3] = 0x44 ^ ((Repeat >> 24) & 0xFF);
CanTxMsg.Data[4] = 0x55 ^ (Repeat & 0xFF);
CanTxMsg.Data[5] = 0x66 ^ ((Repeat >> 8 ) & 0xFF);
CanTxMsg.Data[6] = 0x77 ^ ((Repeat >> 16) & 0xFF);
CanTxMsg.Data[7] = 0x88 ^ ((Repeat >> 24) & 0xFF);
CAN_Transmit(CAN2,&CanTxMsg);
TO = 1000;
while(!CAN_MessagePending(CAN1,1) && (--TO));
if(!TO)
{
R = Repeat;
CanTxMsg1 = CanTxMsg; CanRxMsg1 = CanRxMsg;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1,DISABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN2,DISABLE);
return(0);
}
CAN_Receive(CAN1,1,&CanRxMsg);
for(int i = 0; i < CanRxMsg.DLC; i++)
{
if(CanTxMsg.Data[i] != CanRxMsg.Data[i])
{
CanTxMsg1 = CanTxMsg; CanRxMsg1 = CanRxMsg;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1,DISABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN2,DISABLE);
return(0);
}
LED_Display_All(CanRxMsg.Data[i] & 7);
}
}
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1,DISABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN2,DISABLE);
return(1);
}
Thanks...
2012-06-26 02:04 PM
Can any one help me?...
2012-06-26 02:56 PM
I
haveproblome
a
level
of communication
between two
CAN
cards
STM32F4
DISCOVERY
, after
configuring the
peripheral
CAN1
, CAN
sending
the wrong message
because the
error counter
TEC
equal
to
0xF8.I
wants to
have
the resolution
of this
problem
.
thks2012-06-26 05:57 PM
Can any one help me?...
I'm not a CAN expert, but I think we established that the CAN transceivers on your IAR board were gated with GPIO pins. If neither are set to transmit your signal isn't going anywhere. Are you connecting CAN1(A) to CAN2(B) and CAN2(A) to CAN1(B)? Be careful about ORing registers with arbitrary bit values unless you mask the bits you expect to clear by ANDing first.2012-06-27 06:00 AM
Hi.. Thanks to all to give me solution...
as given example work with CAN1(A) to CAN2(A) i try out CAN1(A) to CAN2(B) and CAN2(A) to CAN1(B)then it showed up other was waiting for Msg just timing miss-match then i add delay then it work. now CAN1(A) to CAN1(B) is also working when added delay.thanks for clive1 for your idea....