![]() |
CROSS Technical Documentation User Manual and Technical Doc.
INFN Milano Bicocca
|
Can Bus operation
SUMMARY:
CAN bus, as well I2C, is a communication protocol based on the CMSIS drivers. Adaptation and use of some drivers is exploited, as it will be explained in the following. First of all it needs to read the hw parte of the the address of the board at some pins of the microcontroller. The addresses are set by means of some switches and the function to be used within the initialization function is lettura_indirizzi_CAN(). The function returns a char with the hw address.
After the communication is completed, either transmission or reception, the interrupt call the CAN_SignalObjectEvent() and CAN_SignalUnitEvent() that have as an input the var event that containes some flags.
The flags from CAN_SignalUnitEvent() are general from the CAN and are the following:
| Parameter event | Bit | Description |
|---|---|---|
| ARM_CAN_EVENT_UNIT_INACTIVE | 0 | Unit entered Inactive state. |
| ARM_CAN_EVENT_UNIT_ACTIVE | 1 | Unit entered Error Active state. |
| ARM_CAN_EVENT_UNIT_WARNING | 2 | Unit entered Error Warning state (one or both error counters >= 96). |
| ARM_CAN_EVENT_UNIT_PASSIVE | 3 | Unit entered Error Passive state. |
| ARM_CAN_EVENT_UNIT_BUS_OFF | 4 | Unit entered Bus-off state. |
CAN_SignalObjectEvent() merely marks the ened of operation and the event var that generates is replicated to the global evento_CAN with the flags that summarazies the results from the objcet under consideration, reception or transmission. In addition to the var event also the var obj_idx is a mark of the data transmission or reception.
The flags of evento_CAN have the following meaning:
| Parameter event | Bit | Description |
|---|---|---|
| ARM_CAN_EVENT_SEND_COMPLETE | 1 << 0 | Message was sent successfully by the obj_idx object. |
| ARM_CAN_EVENT_RECEIVE | 1 << 1 | Message was received successfully by the obj_idx object. |
| ARM_CAN_EVENT_RECEIVE_OVERRUN | 1 << 2 | Message was overwritten before it was read on the obj_idx object. |
The function CAN_Inizialize() is used once to set the CAN into operation. The speed of the bus is defined in CAN_speed. In CAN_Inizialize() the hw address is exploited to compose the final 29 bis long address.
To communicate with the CAN bus we exploit part of the structure of functions from CMSIS. The structure typedef is this:
We use only CAN1 which is defined here:
We exploit mainly CAN1_MessageSend, for transmission, CAN1_MessageRead, for reception. If a polling is needed tehere are 3 varaibles that can be used. The first was mentioned above and is evento_CAN that assumes value according to Table Table_interrupt_obj_event. This variable marks a concluded reception or transmission. Other 2 boolean variables have been introduced, messaggio_CAN_arrivato and messaggio_CAN_spedito that are set to true when the operation is conlcuded. In case these 2 variables are used they need to be set to false just before the CAN operation is started.
The codes for CAN bus is at: