Got MCP2521 to work
This commit is contained in:
@@ -31,6 +31,21 @@
|
||||
|
||||
#define EXTERNAL_TRIGGER GPIO_NUM_26
|
||||
|
||||
void onRX(void *arg) {
|
||||
MCP2521_Command_Interface *mcp2521 = (MCP2521_Command_Interface *)arg;
|
||||
|
||||
rx_info info = mcp2521->get_rx_id(MCP2521_RX_BUFFER::RXB0);
|
||||
uint8_t data[8];
|
||||
|
||||
mcp2521->read_rx_buf(MCP2521_RX_BUFFER::RXB0, MCP2521_BUFFER_TYPE::DATA, data, info.length);
|
||||
|
||||
printf("RX: (%x) ", info.id);
|
||||
for (int i = 0; i < info.length; i++) {
|
||||
printf("%x ", data[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
extern "C" void app_main() {
|
||||
printf("Hello world!\n");
|
||||
|
||||
@@ -57,24 +72,28 @@ extern "C" void app_main() {
|
||||
|
||||
MCP2521_Command_Interface mcp2521(&hardware_mcp2521);
|
||||
|
||||
uint8_t data[4] = {0xf0, 0x42, 0x13, 0x37};
|
||||
|
||||
gpio_set_level(EXTERNAL_TRIGGER, false);
|
||||
printf("CANCTRL: %x\n", mcp2521.read_reg(MCP2521_CANCTRL));
|
||||
printf("RX_STATUS: %x\n", mcp2521.read_rx_status());
|
||||
printf("STATUS: %x\n", mcp2521.read_status());
|
||||
mcp2521.reset();
|
||||
mcp2521.enable_interrupts(true, true, true, true, true, true, true, true);
|
||||
|
||||
uint8_t data[16];
|
||||
hardware_mcp2521.read(MCP2521_OP_READ, data, 16, MCP2521_RXB0CTRL);
|
||||
mcp2521.register_rx0_handler(onRX, &mcp2521);
|
||||
mcp2521.register_rx1_handler(onRX, &mcp2521);
|
||||
mcp2521.set_mode_of_operation(MCP2521_OPERATION_MODE::LOOPBACK, true);
|
||||
|
||||
for(int i=0; i<0x10; i++) {
|
||||
printf("%x ", i);
|
||||
for(int j=0; j<8; j++) {
|
||||
printf("%u", (data[i] >> (7-j)) & 1);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
vTaskDelay(3 / portTICK_PERIOD_MS);
|
||||
|
||||
gpio_set_level(EXTERNAL_TRIGGER, true);
|
||||
mcp2521.prepare_tx(
|
||||
MCP2521_TX_BUFFER::TXB0, 0x042, data, 4, false, false);
|
||||
|
||||
mcp2521.request_to_send(MCP2521_TX_BUFFER::TXB0);
|
||||
|
||||
mcp2521.set_tx_id(MCP2521_TX_BUFFER::TXB0, 0x041, false);
|
||||
mcp2521.request_to_send(MCP2521_TX_BUFFER::TXB0);
|
||||
|
||||
|
||||
vTaskDelay(20 / portTICK_PERIOD_MS);
|
||||
|
||||
bool flag = true;
|
||||
while (true) {
|
||||
|
||||
Reference in New Issue
Block a user