init can bus
This commit is contained in:
parent
9c3f8e0b3f
commit
6adf5dca28
5 changed files with 180 additions and 0 deletions
38
can_bus.h
Normal file
38
can_bus.h
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
#include "boards/pico.h"
|
||||
#include "hardware/spi.h"
|
||||
#include "pico/stdlib.h"
|
||||
#include "pico/time.h"
|
||||
|
||||
// 16MHz 125Kbps
|
||||
#define MCP_CFG1 (0x03)
|
||||
#define MCP_CFG2 (0xF0)
|
||||
#define MCP_CFG3 (0x86)
|
||||
|
||||
typedef struct {
|
||||
spi_inst_t *CHANNEL;
|
||||
uint8_t CS_PIN;
|
||||
// uint8_t TX_PIN;
|
||||
// uint8_t RX_PIN;
|
||||
// uint8_t SCK_PIN;
|
||||
// uint32_t SPI_CLOCK;
|
||||
} mcp2515_config;
|
||||
|
||||
struct can_frame {
|
||||
uint32_t can_id; // 32 bit CAN_ID + EFF/RTR/ERR flags
|
||||
char can_dlc; // frame payload length in byte (0 .. CAN_MAX_DLEN) */
|
||||
char data[8]; // msg
|
||||
};
|
||||
|
||||
enum MCP_ERROR {
|
||||
ERROR_OK = 0,
|
||||
ERROR_FAIL = 1,
|
||||
ERROR_ALLTXBUSY = 2,
|
||||
ERROR_FAILINIT = 3,
|
||||
ERROR_FAILTX = 4,
|
||||
ERROR_NOMSG = 5
|
||||
};
|
||||
|
||||
void mcp2515_init(mcp2515_config *config, uint8_t cs_pin, uint8_t tx_pin,
|
||||
uint8_t rx_pin, uint8_t sck_pin, spi_inst_t *spi_inst);
|
||||
enum MCP_ERROR sendMessage(const struct can_frame *frame);
|
||||
enum MPC_ERROR readMessage(struct can_frame *frame);
|
||||
Loading…
Add table
Add a link
Reference in a new issue