|
piMCP2515
A library for controlling an MCP2515 on the Raspberry Pi and Raspberry Pi Pico
|
These functions handle initialization and configuration. More...
Functions | |
| int | mcp2515_bitrate_simplified (pi_mcp2515_t *pi_mcp2515, uint16_t baud_rate_kbps) |
| A simplified bitrate setting function. | |
| int | mcp2515_bitrate_full_optional (pi_mcp2515_t *pi_mcp2515, uint16_t baud_rate_kbps, uint8_t sjw, uint8_t prescaler, uint8_t prseg_tqps, uint8_t phseg_tqps1, uint8_t phseg_tqps2, bool sof, bool wakfil, bool sam, bool btlmode) |
| Configure the bitrate and all other CNF register stored parameters. | |
| int | mcp2515_cnf_set (pi_mcp2515_t *pi_mcp2515, uint8_t cnf1, uint8_t cnf2, uint8_t cnf3) |
| Set the values of all CNF register. | |
| uint8_t | mcp2515_cnf_get (pi_mcp2515_t *pi_mcp2515, uint8_t cnf) |
| Get the value of a CNF register. | |
| int | mcp2515_init (pi_mcp2515_t **pi_mcp2515, uint8_t spi_channel, uint8_t tx_pin, uint8_t rx_pin, uint8_t sck_pin, uint8_t cs_pin, uint32_t spi_clock, uint8_t osc_mhz) |
| Setup and prepare a pi_mcp2515_t structure based on the parameters provided. | |
| void | mcp2515_conf_spi_devpath (pi_mcp2515_t *pi_mcp2515, char *spidev_path) |
| Override the default path for the spi device (ex /dev/spi0). | |
| void | mcp2515_conf_gpio_devpath (pi_mcp2515_t *pi_mcp2515, char *gpiodev_path) |
| Override the default path for the gpio device (ex /dev/gpio0). | |
| void | mcp2515_free (pi_mcp2515_t *pi_mcp2515) |
| Cleanup after everything. | |
These functions handle initialization and configuration.
| int mcp2515_bitrate_full_optional | ( | pi_mcp2515_t * | pi_mcp2515, |
| uint16_t | baud_rate_kbps, | ||
| uint8_t | sjw, | ||
| uint8_t | prescaler, | ||
| uint8_t | prseg_tqps, | ||
| uint8_t | phseg_tqps1, | ||
| uint8_t | phseg_tqps2, | ||
| bool | sof, | ||
| bool | wakfil, | ||
| bool | sam, | ||
| bool | btlmode ) |
Configure the bitrate and all other CNF register stored parameters.
This function accepts all possible configurable options, while mcp2515_bitrate_simplified can be used for a simplified process.
TODO first draft. Test/validate/fix. Make sure this is right.
| pi_mcp2515 | the piMCP2515 handle. |
| baud_rate_kbps | the baud rate to use in kbps. Commonly either 500 or 1000. |
| sjw | the synchronization jump width in Tqs (1-4). |
| prescaler | the prescaler divisor (0-63) |
| prseg_tqps | the prop segment Tqs/segment |
| phseg_tqps1 | the phase segment 1 Tqs/segment |
| phseg_tqps2 | the phase segment 2 Tqs/segment |
| sof | if start-of-frame signal is enabled. |
| wakfil | if wakeup filter should be enabled. |
| sam | is bus line should be sampled 3 times at sample point (otherwise it is sampled once). |
| btlmode | if BTLMODE is enabled. true: PS2 length is determined by PHSEG2[2:0] (PHSEG2 values originate from phseg_tqps2). false: PS2 length is the greater of PS1 and IPT (2 Tqs) |
| int mcp2515_bitrate_simplified | ( | pi_mcp2515_t * | pi_mcp2515, |
| uint16_t | baud_rate_kbps ) |
A simplified bitrate setting function.
| pi_mcp2515 | the piMCP2515 handle. |
| baud_rate_kbps | the baud rate to use in kbps. Commonly either 500 or 1000. |
| uint8_t mcp2515_cnf_get | ( | pi_mcp2515_t * | pi_mcp2515, |
| uint8_t | cnf ) |
Get the value of a CNF register.
| pi_mcp2515 | the piMCP2515 handle. |
| cnf | The CNF register index such that cnf being 1 will fetch from CNF1, etc. |
| int mcp2515_cnf_set | ( | pi_mcp2515_t * | pi_mcp2515, |
| uint8_t | cnf1, | ||
| uint8_t | cnf2, | ||
| uint8_t | cnf3 ) |
Set the values of all CNF register.
| pi_mcp2515 | the piMCP2515 handle. |
| cnf1 | the value to use for the CNF1 register. |
| cnf2 | the value to use for the CNF2 register. |
| cnf3 | the value to use for the CNF3 register. |
| void mcp2515_conf_gpio_devpath | ( | pi_mcp2515_t * | pi_mcp2515, |
| char * | gpiodev_path ) |
Override the default path for the gpio device (ex /dev/gpio0).
NOOP unless built for spidev.
This function generally will not need to be used as the library should be able to figure out the device patch. Use this only if it can't in your use case. If it is unable to find the path for you, please open an issue on the project with the details so that can be fixed.
| pi_mcp2515 | the piMCP2515 handle. |
| gpiodev_path | the alternate GPIO device path to use. |
| void mcp2515_conf_spi_devpath | ( | pi_mcp2515_t * | pi_mcp2515, |
| char * | spidev_path ) |
Override the default path for the spi device (ex /dev/spi0).
NOOP unless built for spidev.
This function generally will not need to be used as the library should be able to figure out the device patch. Use this only if it can't in your use case. If it is unable to find the path for you, please open an issue on the project with the details so that can be fixed.
| pi_mcp2515 | the piMCP2515 handle. |
| spidev_path | the alternate SPI device path to use. |
| void mcp2515_free | ( | pi_mcp2515_t * | pi_mcp2515 | ) |
Cleanup after everything.
| pi_mcp2515 | the piMCP2515 handle. |
| int mcp2515_init | ( | pi_mcp2515_t ** | pi_mcp2515, |
| uint8_t | spi_channel, | ||
| uint8_t | tx_pin, | ||
| uint8_t | rx_pin, | ||
| uint8_t | sck_pin, | ||
| uint8_t | cs_pin, | ||
| uint32_t | spi_clock, | ||
| uint8_t | osc_mhz ) |
Setup and prepare a pi_mcp2515_t structure based on the parameters provided.
This will still require one of the bitrate setting functions or mcp2515_cnf_set to be used to set up the CNF registers.
| pi_mcp2515 | the piMCP2515 handle. |
| spi_channel | the SPI channel to use which may be 0 or 1. |
| sck_pin | the SCK pin for SPI communication. |
| tx_pin | the TX pin for SPI communication. |
| rx_pin | the RX pin for SPI communication. |
| spi_clock | the frequency to use for SPI communication in Hz. |
| osc_mhz | the frequency of the MCP2515 oscillator in MHz. |
| cs_pin | the GPIO pin to use for SPI chip select. |