📄 mcp2510t.c
字号:
/*
** Copyright (C)1999 KVASER AB, http://www.kvaser.com
** This code may be freely distrubuted and used if the source is indicated.
**
*/
#include <stdio.h>
#include <conio.h>
#include "inc\std.h"
#include "inc\spi.h"
#include "inc\spi_mcp.h"
#include "inc\mcp2510.h"
#include "inc\mcp2510t.h"
/*
** Read all registers in the MCP2510 and print them in tabular form.
*/
void mcp_read_all ( void )
{
uchar i, j;
uchar Store;
printf("Reading all registers in the MCP2510...\n\r" );
SPI_mcp_RD_address(0); // Makes a SPI_mcp_select()
for (j =0; j < 8 ; j++ ) {
printf("Address %02X to %02X: ", (j*16), (j*16+15) );
for (i=0; i < 0x10 ; i++ ) {
Store = SPI_putch(i);
printf("%02X ", Store );
}
printf("\n\r");
}
SPI_mcp_unselect();
Store = SPI_mcp_RD_status(); // Makes a SPI_mcp_select()
printf("Status = 0x%02x\n\r", Store );
SPI_mcp_unselect();
mcp_read(CLKCTRL,&Store,1); // Makes a SPI_mcp_select()
printf("Canctrl = 0x%02x\n\r", Store );
}
/*
** Read one of the CAN transmit or receive buffers in the MCP2510.
** The result is printed.
*/
void mcp_read_buffer( uchar buffer )
{
uchar loopCnt, dlc, rtr, ext;
uchar databytes[8];
unsigned long can_id;
mcp_read_can ( buffer, &ext, &can_id, &dlc, &rtr, databytes );
if( ext == 1 ) {
printf("CAN Id = 0x%08lX (Extended)", can_id);
} else {
printf("CAN Id = 0x%04X (Standard)", (unsigned int) can_id );
}
printf(", with dlc=%d and RTR=%d\n\r", dlc, rtr );
if (buffer > 3) {
printf("Data in receive buffer %d is:", buffer-3 );
} else {
printf("Data in transmit buffer %d is:", buffer );
}
for ( loopCnt=0 ; loopCnt < dlc ; loopCnt++ ) {
printf(" %02X", databytes[loopCnt] );
}
printf("\n\r");
}
/*
** Read one of the transmit buffers in the MCP2510.
*/
int mcp_read_tbuf ( uchar buffer )
{
if ( (buffer < 1) || (buffer > 3) ) {
printf("The only buffers supported are 1,2 and 3, not %d\n\r", buffer );
return 255;
}
mcp_read_buffer( buffer );
return 0;
}
/*
** Read one of the receive buffers in the MCP2510.
*/
int mcp_read_rbuf ( uchar buffer )
{
if ( (buffer < 1) || (buffer > 2) ) {
printf("The only receive buffers supported are 1 and 2, not %d\n\r",
buffer );
return 255;
}
mcp_read_buffer(buffer + 3);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -