Skip to content

Commit

Permalink
Merge pull request #256 from Infineon/develop
Browse files Browse the repository at this point in the history
SPI SD and timeout I2C
  • Loading branch information
jaenrig-ifx committed Sep 26, 2023
2 parents aabd5af + 6ab96ad commit 4387b47
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
7 changes: 5 additions & 2 deletions libraries/SPI/src/SPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@
//#define USE_SW_SPI

// Define USE_XMC_RELAX_KIT_SD allows to use the SD Lib to communicate with a SD Card over
// the on-board SD Card Slot
//#define USE_XMC_RELAX_KIT_SD
// the on-board SD Card Slot. This feature is only available on XMC4700 RelaxKits.
#if defined(XMC4700_Relax_Kit)
#define USE_XMC_RELAX_KIT_SD
#endif


#define SPI_MODE0 0x00
#define SPI_MODE1 0x01
Expand Down
8 changes: 8 additions & 0 deletions libraries/Wire/src/Wire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,14 @@ uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity, uint32_t iaddres
XMC_I2C_CH_MasterStart(XMC_I2C_config->channel, (txAddress << 1), XMC_I2C_CH_CMD_READ);
}

timeout = WIRE_COMMUNICATION_TIMEOUT;
// wait for ACK or timeout incase no ACK is received, a time-based wait-state is added since XMC devices run at variable frequencies
while(((XMC_I2C_CH_GetStatusFlag(XMC_I2C_config->channel) & XMC_I2C_CH_STATUS_FLAG_ACK_RECEIVED) == 0U) || timeout == 0)
{
delay(1);
timeout--;
}

for (uint8_t count = 0; count < (quantity - 1); count ++)
{
XMC_I2C_CH_MasterReceiveAck(XMC_I2C_config->channel);
Expand Down
8 changes: 4 additions & 4 deletions variants/XMC4700/config/XMC4700_Relax_Kit/pins_arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ extern uint8_t MOSI;
extern uint8_t MISO;
extern uint8_t SCK;

#define PIN_SPI_SS_SD 28
#define PIN_SPI_MOSI_SD 29
#define PIN_SPI_MISO_SD 30
#define PIN_SPI_SCK_SD 31
#define PIN_SPI_SS_SD 26
#define PIN_SPI_MOSI_SD 27
#define PIN_SPI_MISO_SD 28
#define PIN_SPI_SCK_SD 29

static const uint8_t SS_SD = PIN_SPI_SS_SD;
static const uint8_t MOSI_SD = PIN_SPI_MOSI_SD;
Expand Down

0 comments on commit 4387b47

Please sign in to comment.