TTK4155 Ping-pong project
can_driver.c File Reference
#include "general_header.h"
#include "spi_driver.h"
#include "can_driver.h"
#include "MCP2515.h"
#include "mcp_driver.h"
Include dependency graph for can_driver.c:

Functions

int CAN_init (uint16_t mode, uint8_t id)
 
uint8_t CAN_loopback (uint8_t data)
 
void CAN_transfer (uint8_t data)
 
void CAN_send (uint8_t id, int data_byte, int *data)
 
void CAN_transfer_2 (uint8_t data1, uint8_t data2)
 
uint8_t CAN_busywait_reveive (void)
 
uint8_t CAN_check_reveive (void)
 
 ISR (INT2_vect)
 CAN message interupt on receive. More...
 

Variables

volatile bool can_wait_for_receive
 Initialize CAN controller and MCP. More...
 

Detailed Description

Implementation of high level CAN bus controller.

Function Documentation

◆ CAN_busywait_reveive()

uint8_t CAN_busywait_reveive ( void  )

CAN receive function

WAIT FOR RX BUFFER 0 INTERUPT

read RX0 data buffer.

turn off the interrupt flag after reading

◆ CAN_check_reveive()

uint8_t CAN_check_reveive ( void  )
Here is the caller graph for this function:

◆ CAN_init()

int CAN_init ( uint16_t  mode,
uint8_t  id 
)

Trigger interrupt on falling edge on INT2.

Enable interrupt on INT2

< Set ID

< Set mode

Here is the caller graph for this function:

◆ CAN_loopback()

uint8_t CAN_loopback ( uint8_t  data)

SET ARBRITARY VALUES FOR ID AND DATA LENGTH

< Load data into TX0 buffer

WAIT FOR RX BUFFER 0 INTERUPT

◆ CAN_send()

void CAN_send ( uint8_t  id,
int  data_byte,
int *  data 
)

Send message on can bus.

Parameters
idCAN ID to send with
data_byteNumber of bytes (from 1 to 8)
dataPointer with data to send.

< Ready to send function.

Here is the caller graph for this function:

◆ CAN_transfer()

void CAN_transfer ( uint8_t  data)

Send message on can bus.

Parameters
dataData to send on bus
Here is the caller graph for this function:

◆ CAN_transfer_2()

void CAN_transfer_2 ( uint8_t  data1,
uint8_t  data2 
)

SET ARBRITARY VALUES FOR ID AND DATA LENGTH

< Load data into TX0 buffer

< Load data into TX0 buffer

◆ ISR()

ISR ( INT2_vect  )

CAN message interupt on receive.

Variable Documentation

◆ can_wait_for_receive

volatile bool can_wait_for_receive

Initialize CAN controller and MCP.

Can variable to check if ready to receive.

/*!

Parameters
modeChoose between MODE_NORMAL or MODE_LOOPBACK
idInitialize with fixed message ID.