autowp / arduino-mcp2515

Arduino MCP2515 CAN interface library
MIT License
793 stars 279 forks source link

Allow Customization of SPI Clock Speed #74

Closed samc1213 closed 2 years ago

samc1213 commented 2 years ago

I am having trouble at 10MHz with some SPI data corruption. However, at 1MHz SPI clock speed, I am able to read the correct data consistently. The library should allow a customizable SPI clock speed.

TzOk83 commented 2 years ago

You can't have a 10MHz SPI clock on ATMega328P running at 16MHz... max is 8MHz.

samc1213 commented 2 years ago

@TzOk83 thanks - so do you think the default 10MHz is too high? In my pull request I've kept the default at 10MHz but allow users to change it.

TzOk83 commented 2 years ago

According to the ATMega328P documentation, max SCK is fosc/2, so for Arduino Uno/Pro-Mini/Nano it is 8MHz max, as they run at 16MHz.