mcp2510 的 can 总线收发器程序 pcbomb 发表于 2008-6-30 14:47:00 阅读全文(769) | 回复(1) | 引用通告(0) | 编辑 # i nclude # i nclude "mcp2510
h" void mcp_reset(void) { SPI_init_hw(); //设置成SPI 方式 init_can_io(); // SPI_mcp_reset(); // } void mcp_read( unsigned char MCPaddr, unsigned char* readdata, unsigned char length ) { unsigned char loopCnt; SPI_mcp_select(); // Select the MCP device at the SPI bus // Start reading and set first address SPI_mcp_RD_address(MCPaddr); for (loopCnt=0; loopCnt < length; loopCnt++) { // Get a byte and store at pointer *readdata = SPI_putch(MCPaddr); // Increment the pointers to next location // Test++; MCPaddr++; readdata++; } SPI_mcp_unselect(); } void mcp_write( unsigned char MCPaddr, unsigned char* writedata, unsigned char length ) { unsigned char loopCnt; SPI_mcp_select(); // Start