TTK4155 Ping-pong project
|
#include "general_header.h"
#include "spi_driver.h"
#include "can_driver.h"
#include "MCP2515.h"
#include "mcp_driver.h"
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... | |
Implementation of high level CAN bus controller.
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
uint8_t CAN_check_reveive | ( | void | ) |
int CAN_init | ( | uint16_t | mode, |
uint8_t | id | ||
) |
Trigger interrupt on falling edge on INT2.
Enable interrupt on INT2
< Set ID
< Set mode
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
void CAN_send | ( | uint8_t | id, |
int | data_byte, | ||
int * | data | ||
) |
Send message on can bus.
id | CAN ID to send with |
data_byte | Number of bytes (from 1 to 8) |
data | Pointer with data to send. |
< Ready to send function.
void CAN_transfer | ( | uint8_t | data | ) |
Send message on can bus.
data | Data to send on bus |
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 | ( | INT2_vect | ) |
CAN message interupt on receive.
volatile bool can_wait_for_receive |
Initialize CAN controller and MCP.
Can variable to check if ready to receive.
/*!
mode | Choose between MODE_NORMAL or MODE_LOOPBACK |
id | Initialize with fixed message ID. |