diff --git a/src/ACAN2517FD.cpp b/src/ACAN2517FD.cpp index 0ded4da..272ecde 100644 --- a/src/ACAN2517FD.cpp +++ b/src/ACAN2517FD.cpp @@ -171,7 +171,7 @@ static uint16_t u16FromBufferAtIndex (uint8_t ioBuffer [], const uint8_t inIndex //---------------------------------------------------------------------------------------------------------------------- -ACAN2517FD::ACAN2517FD (const CanCmn::eCanBusId busId, +ACAN2517FD::ACAN2517FD (const CanCmn::eCanBusFdId busId, const uint8_t inCS, // CS input of MCP2517FD SPIClass & inSPI, // Hardware SPI object const uint8_t inINT) : // INT output of MCP2517FD @@ -351,7 +351,7 @@ uint32_t ACAN2517FD::begin (const ACAN2517FDSettings & inSettings, } } //----------------------------------- Set full speed clock - mSPISettings = SPISettings (inSettings.sysClock () / 2, MSBFIRST, SPI_MODE0) ; + mSPISettings = SPISettings (8000UL*1000, MSBFIRST, SPI_MODE0) ; //----------------------------------- Checking SPI connection is on (with a full speed clock) // We write and read back 2517 RAM at address 0x400 for (uint32_t i=1 ; (i != 0) && (errorCode == 0) ; i <<= 1) { @@ -1260,3 +1260,18 @@ uint32_t ACAN2517FD::diagInfos (const int inIndex) { // thanks to Flole998 and t } //---------------------------------------------------------------------------------------------------------------------- +//Gpio + void ACAN2517FD::ledRedToggle() { //rxobfOn; avaible on CAN1,2 + if (readRegister8(IOCON_REGISTER) & 0x01) { + ledRedOn(); + } + else{ + ledRedOff(); + } + } + void ACAN2517FD::ledRedOn() { + writeRegister8 (IOCON_REGISTER, 0) ; // write 1 to gpio0 + } + void ACAN2517FD::ledRedOff() { + writeRegister8 (IOCON_REGISTER, 1) ; // write 0 to gpio0 + } \ No newline at end of file diff --git a/src/ACAN2517FD.h b/src/ACAN2517FD.h index 2cff178..cf0583d 100644 --- a/src/ACAN2517FD.h +++ b/src/ACAN2517FD.h @@ -27,7 +27,7 @@ class ACAN2517FD { // CONSTRUCTOR //······················································································································ - public: ACAN2517FD (const CanCmn::eCanBusId busId, + public: ACAN2517FD (const CanCmn::eCanBusFdId busId, const uint8_t inCS, // CS input of MCP2517FD SPIClass & inSPI, // Hardware SPI object const uint8_t inINT) ; // INT output of MCP2517FD @@ -137,7 +137,7 @@ class ACAN2517FD { #endif private: SPISettings mSPISettings ; private: SPIClass & mSPI ; - private: CanCmn::eCanBusId mBusId; + private: CanCmn::eCanBusFdId mBusId; private: const uint8_t mCS ; private: const uint8_t mINT ; private: bool mUsesTXQ ; @@ -173,6 +173,11 @@ class ACAN2517FD { public: uint32_t driverTransmitBufferCount (void) const { return mDriverTransmitBuffer.count () ; } public: uint32_t driverTransmitBufferPeakCount (void) const { return mDriverTransmitBuffer.peakCount () ; } +// Gpio + public: + void ledRedToggle(); + void ledRedOn(); + void ledRedOff(); //······················································································································ // Private methods @@ -308,13 +313,7 @@ class ACAN2517FD { } private: inline void assertCS() { switch (mBusId) { - case CanCmn::eCanBusId::eCan0: - digitalWrite(mCS, LOW); - break; - case CanCmn::eCanBusId::eCan1: - _Mux.can1Cs(); - break; - case CanCmn::eCanBusId::eCan2: + case CanCmn::eCanBusFdId::eCanFd2: _Mux.can2Cs(); break; @@ -324,13 +323,7 @@ class ACAN2517FD { } private: inline void deassertCS() { switch (mBusId) { - case CanCmn::eCanBusId::eCan0: - digitalWrite(mCS, HIGH); - break; - case CanCmn::eCanBusId::eCan1: - _Mux.can1UnCs(); - break; - case CanCmn::eCanBusId::eCan2: + case CanCmn::eCanBusFdId::eCanFd2: _Mux.can2UnCs(); break; default: