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 12 20:54:16 2013 +0000
Revision:
2:fd026fcfde94
Parent:
1:ad71faa09868
Updated 12-11-2013 - attach functions are now usable. Changes to allow the the library to be used with more mbeds (e.g. LPC1768). I have also added new functions/methods which give more information about errors and interrupts.

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 1:ad71faa09868 27 /// Type definition to hold a Seeed Studios CAN-BUS Shield connections and resources structure
Just4pLeisure 1:ad71faa09868 28 struct Seeed_MCP_CAN_Shield {
Just4pLeisure 0:f5d099885d3d 29 SPI spi;
Just4pLeisure 0:f5d099885d3d 30 DigitalOut ncs;
Just4pLeisure 0:f5d099885d3d 31 InterruptIn irq;
Just4pLeisure 0:f5d099885d3d 32 Seeed_MCP_CAN_Shield(SPI _spi_, DigitalOut _ncs_, InterruptIn _irq_) :
Just4pLeisure 0:f5d099885d3d 33 spi(_spi_),
Just4pLeisure 0:f5d099885d3d 34 ncs(_ncs_),
Just4pLeisure 0:f5d099885d3d 35 irq(_irq_)
Just4pLeisure 0:f5d099885d3d 36 {}
Just4pLeisure 0:f5d099885d3d 37 };
Just4pLeisure 2:fd026fcfde94 38 typedef struct Seeed_MCP_CAN_Shield mcp_can_t;
Just4pLeisure 0:f5d099885d3d 39
Just4pLeisure 0:f5d099885d3d 40 /** mcp2515 spi instructions
Just4pLeisure 0:f5d099885d3d 41 */
Just4pLeisure 2:fd026fcfde94 42 void mcpReset(mcp_can_t *obj); // reset the MCP2515 CAN controller chip
Just4pLeisure 0:f5d099885d3d 43
Just4pLeisure 2:fd026fcfde94 44 uint8_t mcpRead(mcp_can_t *obj, // read from a single MCP2512 register
Just4pLeisure 0:f5d099885d3d 45 const uint8_t address);
Just4pLeisure 2:fd026fcfde94 46 void mcpReadMultiple(mcp_can_t *obj, // read multiple, sequential, registers into an array
Just4pLeisure 0:f5d099885d3d 47 const uint8_t address,
Just4pLeisure 0:f5d099885d3d 48 uint8_t values[],
Just4pLeisure 0:f5d099885d3d 49 const uint8_t n);
Just4pLeisure 2:fd026fcfde94 50 void mcpReadBuffer(mcp_can_t *obj, // read the specified receive buffer into an array
Just4pLeisure 0:f5d099885d3d 51 const uint8_t command,
Just4pLeisure 0:f5d099885d3d 52 uint8_t values[],
Just4pLeisure 0:f5d099885d3d 53 const uint8_t n);
Just4pLeisure 2:fd026fcfde94 54 void mcpWrite(mcp_can_t *obj, // write to a single MCP2512 register
Just4pLeisure 0:f5d099885d3d 55 const uint8_t address,
Just4pLeisure 0:f5d099885d3d 56 const uint8_t value);
Just4pLeisure 2:fd026fcfde94 57 void mcpWriteMultiple(mcp_can_t *obj, // write an array into consecutive MCP2515 registers
Just4pLeisure 0:f5d099885d3d 58 const uint8_t address,
Just4pLeisure 0:f5d099885d3d 59 const uint8_t values[],
Just4pLeisure 0:f5d099885d3d 60 const uint8_t n);
Just4pLeisure 2:fd026fcfde94 61 void mcpWriteBuffer(mcp_can_t *obj, // write an array into the specified transmit buffer
Just4pLeisure 0:f5d099885d3d 62 const uint8_t command,
Just4pLeisure 0:f5d099885d3d 63 uint8_t values[],
Just4pLeisure 0:f5d099885d3d 64 const uint8_t n);
Just4pLeisure 2:fd026fcfde94 65 void mcpBufferRTS(mcp_can_t *obj, const uint8_t command); // initiate transmission of the specified MCP2515 transmit buffer
Just4pLeisure 2:fd026fcfde94 66 uint8_t mcpStatus(mcp_can_t *obj); // read the MCP2515's status register
Just4pLeisure 2:fd026fcfde94 67 uint8_t mcpReceiveStatus(mcp_can_t *obj); // read mcp2515's receive status register
Just4pLeisure 2:fd026fcfde94 68 void mcpBitModify(mcp_can_t *obj, // modify bits of a register specified by a mask
Just4pLeisure 0:f5d099885d3d 69 const uint8_t address,
Just4pLeisure 0:f5d099885d3d 70 const uint8_t mask,
Just4pLeisure 0:f5d099885d3d 71 const uint8_t data);
Just4pLeisure 0:f5d099885d3d 72
Just4pLeisure 0:f5d099885d3d 73 #ifdef __cplusplus
Just4pLeisure 0:f5d099885d3d 74 };
Just4pLeisure 0:f5d099885d3d 75 #endif
Just4pLeisure 0:f5d099885d3d 76
Just4pLeisure 0:f5d099885d3d 77 #endif // SEEED_CAN_SPI_H