Skip to main content
aloui
Associate II
May 17, 2009
Question

CAN TX interrupt

  • May 17, 2009
  • 3 replies
  • 2042 views
Posted on May 17, 2009 at 14:26

CAN TX interrupt

    This topic has been closed for replies.

    3 replies

    aloui
    alouiAuthor
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 13:11

    Hello every body,

    I have a trouble in getting CAN transmission interrupt to work.

    How do i activate the interrupt?

    I use this while initialising the NVIC:

    NVIC_InitStructure.NVIC_IRQChannel = USB_HP_CAN_TX_IRQChannel;

    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 192;

    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

    NVIC_Init(&NVIC_InitStructure);

    I am using FREERTOS so i need the priority to be higher than 191 in order to make some features work.

    And each time i want to send data i put it in a queu and then activate the TX interrupt as follow

    void CAN_Write(char* c)

    {

    char* d=c;

    xSemaphoreTake(xCANTXSemaphore,( portTickType ) portMAX_DELAY);

    while(*d!=0)

    {

    xQueueSend(xCANQueuTX, d++,( portTickType ) portMAX_DELAY);

    }

    CAN_ITConfig(CAN_IT_TME, ENABLE);//on active l'interruption d'ecriture

    xSemaphoreGive(xCANTXSemaphore);

    }

    Then in the IRQ i do this:

    void ISR_CANTX()

    {

    CanTxMsg TxMessage;

    portBASE_TYPE xHigherPriorityTaskWoken=pdFALSE ;

    TxMessage.StdId=0x11;

    TxMessage.RTR=CAN_RTR_DATA;

    TxMessage.IDE=CAN_ID_STD;

    TxMessage.DLC=2;

    //Si il y a encore quoi envoyer on envoi

    if(xQueueReceiveFromISR( xRS232QueuTX, &( TxMessage.Data[0] ),&xHigherPriorityTaskWoken))

    {

    CAN_Transmit(&TxMessage);

    }

    else//sinon on desactive cette interruption

    {

    CAN_ITConfig(CAN_IT_TME,DISABLE);

    }

    CAN_ClearITPendingBit(CAN_IT_TME);

    portEND_SWITCHING_ISR( xHigherPriorityTaskWoken );

    }

    I chack the queu, if there is something to send i send it else i disactivate the interrupt.

    I have initialised the interrupts vector to make this routine the one called when an interrupt occurs on USB_HP_CAN_TX_IRQChannel.

    Did i miss something, and am i right to use this IRQChannel and this interrupt: CAN_ITConfig(CAN_IT_TME, ENABLE); ?

    Thanks

    [ This message was edited by: aloui.seifeddine on 12-05-2009 22:59 ]

    amin2
    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 13:12

    Hi Seif,

    The TME interrupt is connected to 3 Flags (RQCP2,RQCP1,RQCP0)

    the description of RQCPx flag is :

    Request Completed for Mailbox x , This bit is set by hardware to signal that the last request for mailbox x has been completed. The request could be a transmit or an abort request. This bit is cleared by software writing 1.

    The TME interrupt is an indicator that the Transmission is done (or aborded). ;)

    Amin

    aloui
    alouiAuthor
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 13:12

    In fact, i think there is a Bug in the STM32. It is written that TME is Transmit Mailbox Empty, but i found that this interrupt occurs when the CAN TX transmission is done!!!