Skip to content

Commit

Permalink
fix: baudrates <= 10000 were not working. This push fixes it
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjuruk committed Jan 5, 2021
1 parent dd845fb commit c744d08
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions Source/CAN_Hw.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*----------------------------------------------------------------------------
/*----------------------------------------------------------------------------
* R T L - C A N D r i v e r
*----------------------------------------------------------------------------
* Name: CAN_Hw.c
Expand Down Expand Up @@ -75,11 +75,17 @@ static CAN_ERROR CAN_hw_set_baudrate (U32 ctrl, U32 baudrate) {
appropriate bit timing */
if (baudrate <= 500000) {
brp = (brp / 18) / baudrate;

/* Load the baudrate registers BTR */
/* so that sample point is at about 72% bit time from bit start */
/* TSEG1 = 12, TSEG2 = 5, SJW = 4 => 1 CAN bit = 18 TQ, sample at 72% */
CAN_set_timing( 12, 5, 4, brp);
if (baudrate <= 10000) {
/* TSEG1 = 3, TSEG2 = 2, SJW = 4 => 1 CAN bit = 18 TQ, sample at 72% */
CAN_set_timing(3, 2, 4, brp*3);
}
else {
/* TSEG1 = 12, TSEG2 = 5, SJW = 4 => 1 CAN bit = 18 TQ, sample at 72% */
CAN_set_timing(12, 5, 4, brp);
}
} else if (baudrate <= 1000000) {
brp = (brp / 9) / baudrate;

Expand Down Expand Up @@ -168,7 +174,7 @@ U32 gCtrl;
U32 gBaudrate;
CAN_ERROR CAN_hw_init (U32 ctrl, U32 baudrate)
{
//徐成
//其냥
#if CAN_ART_Enable

CAN->MCR = CAN_MCR_INRQ;
Expand All @@ -191,7 +197,7 @@ CAN_ERROR CAN_hw_init (U32 ctrl, U32 baudrate)

CAN_ERROR CAN_hw_init_ex (U32 ctrl, U32 baudrate, U8 bArt)
{
//徐成
//其냥
if(bArt > 0)
{
CAN->MCR = CAN_MCR_INRQ;
Expand All @@ -215,7 +221,7 @@ CAN_ERROR CAN_hw_init_ex (U32 ctrl, U32 baudrate, U8 bArt)

CAN_ERROR CAN_hw_reinit(U32 ctrl, U32 baudrate)
{
//CAN强行复位
//CAN퓻契릿貫
CAN->MCR = CAN_MCR_RESET;
CAN->MCR &= ~CAN_MCR_SLEEP;

Expand All @@ -224,7 +230,7 @@ CAN_ERROR CAN_hw_reinit(U32 ctrl, U32 baudrate)

CAN_ERROR CAN_hw_reinit_ex(U32 ctrl, U32 baudrate, U8 bArt)
{
//CAN强行复位
//CAN퓻契릿貫
CAN->MCR = CAN_MCR_RESET;
CAN->MCR &= ~CAN_MCR_SLEEP;

Expand All @@ -247,7 +253,7 @@ CAN_ERROR CAN_hw_start (U32 ctrl)
{

CAN->MCR &= ~CAN_MCR_INRQ; /* normal operating mode, reset INRQ */
//徐成
//其냥
#if CAN_ABOM_Enable
CAN->MCR |= CAN_MCR_ABOM;
#endif
Expand Down Expand Up @@ -510,7 +516,7 @@ CAN_ERROR CAN_hw_rx_object_mask (U32 ctrl, U32 ch, U32 id, U32 mask, CAN_FORMAT
}


//带MASK和INDEX的FILTER
//던MASK뵨INDEX돨FILTER
CAN_ERROR CAN_hw_rx_object_mask_idx (U32 ctrl, U32 ch, U32 id, U32 mask, U8 idx, U8 enable, CAN_FORMAT format)
{
U32 CAN_msgId = 0;
Expand Down Expand Up @@ -630,26 +636,26 @@ void USB_LP_CAN_RX0_IRQHandler (void) {

/*--------------------------- CAN_SetErrCallBack ------------------------------
*
* 设置错误处理回调函数
* 零댄轎뇹잿쀼딧변鑒
*
* 参数: ceh:错误处理函数指针
* 꽝鑒: ceh:댄轎뇹잿변鑒寧濾
*---------------------------------------------------------------------------*/
static CANERRHANDLER gCanErrHandler = NULL;
void CAN_err_config(CANERRHANDLER ceh)
{
//徐成改动
//其냥맣땡
NVIC_InitTypeDef NVIC_InitStructure;

gCanErrHandler = ceh;

//徐成
//其냥
NVIC_InitStructure.NVIC_IRQChannel = CAN_SCE_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);

CAN_ITConfig(CAN_IT_ERR|CAN_IT_EWG|CAN_IT_EPV|CAN_IT_BOF, ENABLE); //错误警告中断屏蔽|错误被动中断屏蔽|上次错误号中断屏蔽|错误中断屏蔽
CAN_ITConfig(CAN_IT_ERR|CAN_IT_EWG|CAN_IT_EPV|CAN_IT_BOF, ENABLE); //댄轎쒸멩櫓뙤팁귁|댄轎굳땡櫓뙤팁귁|늴댄轎뵀櫓뙤팁귁|댄轎櫓뙤팁귁
}

void CAN_SCE_IRQHandler(void)
Expand Down

0 comments on commit c744d08

Please sign in to comment.