This library for Seeed Studio's CAN-BUS Shield has a similar API to mbed's LPC1768 CAN library making it easy to add CAN functionality to mbed systems that support Arduino type 'Shields. This Beta release of my CAN-BUS Library is largely working but lacks interrupt 'attach' functions.

Dependents:   Seeed_CAN_Hello_World ws-canrecv-1 CAN_SPI_modulo

Fork of SEEED_CAN by Sophie Dexter

Committer:
Just4pLeisure
Date:
Tue Nov 05 22:37:35 2013 +0000
Revision:
0:f5d099885d3d
Child:
1:ad71faa09868
Beta release of a CAN-BUS library for Seeed Studios' CAN BUS Shield

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Just4pLeisure 0:f5d099885d3d 1 /* seeed_can_spi.h
Just4pLeisure 0:f5d099885d3d 2 * Copyright (c) 2013 Sophie Dexter
Just4pLeisure 0:f5d099885d3d 3 *
Just4pLeisure 0:f5d099885d3d 4 * Licensed under the Apache License, Version 2.0 (the "License");
Just4pLeisure 0:f5d099885d3d 5 * you may not use this file except in compliance with the License.
Just4pLeisure 0:f5d099885d3d 6 * You may obtain a copy of the License at
Just4pLeisure 0:f5d099885d3d 7 *
Just4pLeisure 0:f5d099885d3d 8 * http://www.apache.org/licenses/LICENSE-2.0
Just4pLeisure 0:f5d099885d3d 9 *
Just4pLeisure 0:f5d099885d3d 10 * Unless required by applicable law or agreed to in writing, software
Just4pLeisure 0:f5d099885d3d 11 * distributed under the License is distributed on an "AS IS" BASIS,
Just4pLeisure 0:f5d099885d3d 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Just4pLeisure 0:f5d099885d3d 13 * See the License for the specific language governing permissions and
Just4pLeisure 0:f5d099885d3d 14 * limitations under the License.
Just4pLeisure 0:f5d099885d3d 15 */
Just4pLeisure 0:f5d099885d3d 16 #ifndef _SEEED_CAN_SPI_H_
Just4pLeisure 0:f5d099885d3d 17 #define _SEEED_CAN_SPI_H_
Just4pLeisure 0:f5d099885d3d 18
Just4pLeisure 0:f5d099885d3d 19 #include "seeed_can_defs.h"
Just4pLeisure 0:f5d099885d3d 20
Just4pLeisure 0:f5d099885d3d 21 #ifdef __cplusplus
Just4pLeisure 0:f5d099885d3d 22 extern "C" {
Just4pLeisure 0:f5d099885d3d 23 #endif
Just4pLeisure 0:f5d099885d3d 24
Just4pLeisure 0:f5d099885d3d 25 /** CAN driver typedefs
Just4pLeisure 0:f5d099885d3d 26 */
Just4pLeisure 0:f5d099885d3d 27 struct Seeed_MCP_CAN_Shield {
Just4pLeisure 0:f5d099885d3d 28 SPI spi;
Just4pLeisure 0:f5d099885d3d 29 DigitalOut ncs;
Just4pLeisure 0:f5d099885d3d 30 InterruptIn irq;
Just4pLeisure 0:f5d099885d3d 31 Seeed_MCP_CAN_Shield(SPI _spi_, DigitalOut _ncs_, InterruptIn _irq_) :
Just4pLeisure 0:f5d099885d3d 32 spi(_spi_),
Just4pLeisure 0:f5d099885d3d 33 ncs(_ncs_),
Just4pLeisure 0:f5d099885d3d 34 irq(_irq_)
Just4pLeisure 0:f5d099885d3d 35 {}
Just4pLeisure 0:f5d099885d3d 36 };
Just4pLeisure 0:f5d099885d3d 37 typedef struct Seeed_MCP_CAN_Shield can_t;
Just4pLeisure 0:f5d099885d3d 38
Just4pLeisure 0:f5d099885d3d 39 /** mcp2515 spi instructions
Just4pLeisure 0:f5d099885d3d 40 */
Just4pLeisure 0:f5d099885d3d 41 void mcpReset(can_t *obj); // reset the MCP2515 CAN controller chip
Just4pLeisure 0:f5d099885d3d 42
Just4pLeisure 0:f5d099885d3d 43 uint8_t mcpRead(can_t *obj, // read from a single MCP2512 register
Just4pLeisure 0:f5d099885d3d 44 const uint8_t address);
Just4pLeisure 0:f5d099885d3d 45 void mcpReadMultiple(can_t *obj, // read multiple, sequential, registers into an array
Just4pLeisure 0:f5d099885d3d 46 const uint8_t address,
Just4pLeisure 0:f5d099885d3d 47 uint8_t values[],
Just4pLeisure 0:f5d099885d3d 48 const uint8_t n);
Just4pLeisure 0:f5d099885d3d 49 void mcpReadBuffer(can_t *obj, // read the specified receive buffer into an array
Just4pLeisure 0:f5d099885d3d 50 const uint8_t command,
Just4pLeisure 0:f5d099885d3d 51 uint8_t values[],
Just4pLeisure 0:f5d099885d3d 52 const uint8_t n);
Just4pLeisure 0:f5d099885d3d 53 void mcpWrite(can_t *obj, // write to a single MCP2512 register
Just4pLeisure 0:f5d099885d3d 54 const uint8_t address,
Just4pLeisure 0:f5d099885d3d 55 const uint8_t value);
Just4pLeisure 0:f5d099885d3d 56 void mcpWriteMultiple(can_t *obj, // write an array into consecutive MCP2515 registers
Just4pLeisure 0:f5d099885d3d 57 const uint8_t address,
Just4pLeisure 0:f5d099885d3d 58 const uint8_t values[],
Just4pLeisure 0:f5d099885d3d 59 const uint8_t n);
Just4pLeisure 0:f5d099885d3d 60 void mcpWriteBuffer(can_t *obj, // write an array into the specified transmit buffer
Just4pLeisure 0:f5d099885d3d 61 const uint8_t command,
Just4pLeisure 0:f5d099885d3d 62 uint8_t values[],
Just4pLeisure 0:f5d099885d3d 63 const uint8_t n);
Just4pLeisure 0:f5d099885d3d 64 void mcpBufferRTS(can_t *obj, const uint8_t command); // initiate transmission of the specified MCP2515 transmit buffer
Just4pLeisure 0:f5d099885d3d 65 uint8_t mcpStatus(can_t *obj); // read the MCP2515's status register
Just4pLeisure 0:f5d099885d3d 66 uint8_t mcpReceiveStatus(can_t *obj); // read mcp2515's receive status register
Just4pLeisure 0:f5d099885d3d 67 void mcpBitModify(can_t *obj, // modify bits of a register specified by a mask
Just4pLeisure 0:f5d099885d3d 68 const uint8_t address,
Just4pLeisure 0:f5d099885d3d 69 const uint8_t mask,
Just4pLeisure 0:f5d099885d3d 70 const uint8_t data);
Just4pLeisure 0:f5d099885d3d 71
Just4pLeisure 0:f5d099885d3d 72 #ifdef __cplusplus
Just4pLeisure 0:f5d099885d3d 73 };
Just4pLeisure 0:f5d099885d3d 74 #endif
Just4pLeisure 0:f5d099885d3d 75
Just4pLeisure 0:f5d099885d3d 76 #endif // SEEED_CAN_SPI_H