mcp2515.c in AVR+mcp2515code.rar


MCP2515 using the CAN communications code, suitable for 8-bit, 16-bit AVR Single...Original Link
    Sponsored links

			
/******************************************************************************
 * 
 * Controller Area Network (CAN) Demo-Application
 * Atmel AVR with Microchip MCP2515 
 * 
 * Copyright (C) 2005 Martin THOMAS, Kaiserslautern, Germany
 * <eversmith@heizung-thomas.de>
 * http://www.siwawi.arubi.uni-kl.de/avr_projects
 *
 *****************************************************************************
 *
 * File    : mcp2515.c
 * Version : 0.9
 * 
 * Summary : MCP2515 "low-level" driver
 *
 * Parts of this code are adapted from a MCP2510 sample-application 
 * by KVASER AB, http://www.kvaser.com (KVASER-code is marked as free)
 *
 * This code-module is free to use but you have to keep the copyright
 * notice.
 *
 *****************************************************************************/

#include <inttypes.h>

#include "spi.h"
#include "delay.h"
#include "mcp2515.h"
#include "mcp2515_defs.h"
#include "mcp2515_bittime.h"

#include "can.h"

#if (MCPDEBUG)
#include "termio.h"
#include "debughelper.h"
#endif

void mcp2515_reset(void)
{
	MCP2515_SELECT();
	spi_readwrite(MCP_RESET);
	MCP2515_UNSELECT();
	delay_ms(10); // rough - but > 128 MCP clock-cycles
}

uint8_t mcp2515_readRegister(const uint8_t address)
{
	uint8_t ret;
	
	MCP2515_SELECT();
	spi_readwrite(MCP_READ);
	spi_readwrite(address);
	ret = spi_read();
	MCP2515_UNSELECT();
	
	return ret;
}

void mcp2515_readRegisterS(const uint8_t address, 
	uint8_t values[], const uint8_t n)
{
	uint8_t i;
	
	MCP2515_SELECT();
	spi_readwrite(MCP_READ);
	spi_readwrite(address);
	// mcp2515 has auto-increment of address-pointer
	for (i=0; i<n; i++) {
		values[i] = spi_read();
	}
	MCP2515_UNSELECT();
}

void mcp2515_setRegister(const uint8_t address, const uint8_t value)
{
	MCP2515_SELECT();
	spi_readwrite(MCP_WRITE);
	spi_readwrite(address);
	spi_readwrite(value);
	MCP2515_UNSELECT();
}

void mcp2515_setRegisterS(const uint8_t address, 
	const uint8_t values[], const uint8_t n)
{
	uint8_t i			

			...
			...
			... to be continued.

  This is a preview. To get the complete source file, 
  please click here to download the whole source code package.

			
			


Project Files

    Sponsored links
NameSizeDate
 mcpcanavr.pnproj826.00 B03-02-05 04:01
 makefile10.98 kB17-03-05 03:52
 main.c5.71 kB19-04-05 16:38
 mcp2515_bittime.h3.36 kB24-03-05 02:15
 delay.c1.06 kB20-01-05 06:40
 delay.h1.70 kB20-01-05 06:38
 uart.c13.56 kB21-01-05 04:22
 uart.h6.64 kB21-01-05 02:14
 debughelper.h212.00 B01-08-08 16:22
 debughelper.c361.00 B22-01-05 17:42
 gpio.c408.00 B25-01-05 00:56
 gpio.h377.00 B03-02-05 00:48
 terminal.c6.92 kB19-04-05 16:33
 terminal.h349.00 B03-02-05 02:51
 termio.c1.55 kB19-04-05 16:34
 termio.h880.00 B22-01-05 17:42
 spi.c1.13 kB09-03-05 04:04
 spi.h681.00 B15-03-05 01:21
 timebase.h466.00 B03-02-05 02:46
 timebase.c1.25 kB19-04-05 16:35
 main_elf.aps6.88 kB18-02-05 18:16
 LICENSE.txt1.15 kB19-04-05 16:41
 mcp2515.c10.89 kB31-07-08 18:23
 mcp2515.h1.95 kB19-04-05 15:24
 mcp2515_defs.h4.93 kB19-04-05 15:59
 can.c5.74 kB19-04-05 16:04
 can.h1.59 kB19-04-05 15:50
 mcp2515.IMB12.00 kB27-06-08 17:33
 mcp2515.IMD448.00 B27-06-08 17:33
 mcp2515.IAB24.00 kB27-06-08 17:33
 mcp2515.IAD568.00 B27-06-08 17:33
 mcp2515.PR7.81 kB27-06-08 17:33
 mcp2515.PS71.89 kB29-08-08 21:43
 mcp2515.PFI96.00 B01-08-08 22:38
 mcp2515.PO776.00 B01-08-08 22:38
 mcp2515.PRI47.94 kB27-06-08 17:33
 mcp2515.WK351.18 kB29-08-08 21:43
 mcp2515.SearchResults150.00 B31-07-08 18:26
 <src>0.00 B25-08-08 19:56
 <AVR+mcp2515源码>0.00 B25-08-08 19:56
...

Related Items

    Sponsored links