I'm stuck with the CAN bus, I have a board STM32F405 I succesfully managed to assign the PIN remap for using portB CAN2 Tx and RX. I found and example about how to initialize the bus, but with an oscilloscope I only have on the TX a sequence of 7 one (no CAN ID, nor packet data).
I have an external quartz of 12Mhz so I changed the config like below
#define STM32F4xx_MCUCONF
/*
* HAL driver system settings.
*/
#define STM32_NO_INIT FALSE
#define STM32_HSI_ENABLED TRUE
#define STM32_LSI_ENABLED TRUE
#define STM32_HSE_ENABLED TRUE
#define STM32_LSE_ENABLED FALSE
#define STM32_CLOCK48_REQUIRED TRUE
#define STM32_SW STM32_SW_PLL
#define STM32_PLLSRC STM32_PLLSRC_HSE
#define STM32_PLLM_VALUE 12
#define STM32_PLLN_VALUE 336
#define STM32_PLLP_VALUE 4
#define STM32_PLLQ_VALUE 7
#define STM32_HPRE STM32_HPRE_DIV1
#define STM32_PPRE1 STM32_PPRE1_DIV2 //
#define STM32_PPRE2 STM32_PPRE2_DIV1 //
#define STM32_RTCSEL STM32_RTCSEL_LSI
#define STM32_RTCPRE_VALUE 8
#define STM32_MCO1SEL STM32_MCO1SEL_HSI
#define STM32_MCO1PRE STM32_MCO1PRE_DIV1
#define STM32_MCO2SEL STM32_MCO2SEL_SYSCLK
#define STM32_MCO2PRE STM32_MCO2PRE_DIV5
#define STM32_I2SSRC STM32_I2SSRC_CKIN
#define STM32_PLLI2SN_VALUE 192
#define STM32_PLLI2SR_VALUE 2 //
#define STM32_PVD_ENABLE FALSE
#define STM32_PLS STM32_PLS_LEV0
#define STM32_BKPRAM_ENABLE FALSE
#define STM32_CAN_USE_CAN1 TRUE
#define STM32_CAN_USE_CAN2 TRUE
//those settings must achieves 500000 bps with a bus of 42Mhz
static const CANConfig cancfg = {
/*.mcr = */ CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP,
/*.btr = */ CAN_BTR_SJW(0) | CAN_BTR_TS2(1) | CAN_BTR_LBKM |
CAN_BTR_TS1(8) | CAN_BTR_BRP(6)
};
canStart(&CAND2, &cancfg); //ruft can_lld_start(..) auf
static CANTxFrame txmsg;
while(1)
{
txmsg.IDE = CAN_IDE_STD;
txmsg.EID = 0x755;
txmsg.RTR = CAN_RTR_DATA;
txmsg.DLC = 8;
txmsg.data32[0] = 0x0;//velocità
txmsg.data32[1] = 0xFFFFFFFF;
msg_t rc = canTransmit(&CAND2, CAN_ANY_MAILBOX, &txmsg, MS2ST(100));
chprintf((BaseSequentialStream*)&SD1, "sending CAN msg returned rc: %d, can state: %d, tx_empty_before: %d\n\r",
rc, CAND2.state, tx_empty_before);
}
The result of the function gave always rc = -1, CAND2.state = 3 and[code][/code] tx_empty_before = 0
Is there any function to check the status of CAN_MSR register?
Many thanks to whatever person who will help me.
I successfully managed to read from two SPI and send the data with the UART, the only thing I'm lacking is the CAN
Enrico