LoginSignup
0
1

More than 1 year has passed since last update.

nRF5x シリーズで I2C と SPIを同時に使用する場合の SDK修正点

Last updated at Posted at 2022-04-04

はじめに
Nordic nRF5x シリーズにて SDK に収められている サンプルコードで SPI と I2C を同時に使用する場合の注意点を記す


nRF5x の SDK サンプルコードに収められている中で
SPI については、以下が

C:\nRF5_SDK_17.x.x_xxx\examples\peripheral\spi

I2Cについては、以下が

C:\nRF5_SDK_17.x.x_xxx\examples\peripheral\twi_sensor

サンプルコードとして記載されている。

これを単純に合体(ソースコード & sdk_config.h) させると以下の様なエラーが出る。

'NRF_DRV_SPI_INSTANCE_0' undeclared here (not in a function); did you mean 'NRF_DRV_SPI_INSTANCE_1'?

この理由は、TWI(I2C) instance ID と SPI INSTANCE ID が共に 0 だからである。

故に、お互いに異なる値 (0 と 1) に設定する。ところが 新たなエラーとして 以下が出る。

multiple definition of `SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler'

これを回避するには、 sdk_config.h を下記の様に修正する必要がある

[修正前]

// <e> SPI0_ENABLED - Enable SPI0 instance
//==========================================================
#ifndef SPI0_ENABLED
#define SPI0_ENABLED 1
#endif
// <q> SPI0_USE_EASY_DMA  - Use EasyDMA
 

#ifndef SPI0_USE_EASY_DMA
#define SPI0_USE_EASY_DMA 1
#endif

// </e>

// <e> SPI1_ENABLED - Enable SPI1 instance
//==========================================================
#ifndef SPI1_ENABLED
#define SPI1_ENABLED 0
#endif
// <q> SPI1_USE_EASY_DMA  - Use EasyDMA
 

#ifndef SPI1_USE_EASY_DMA
#define SPI1_USE_EASY_DMA 1
#endif

[修正後]

// <e> SPI0_ENABLED - Enable SPI0 instance
//==========================================================
#ifndef SPI0_ENABLED
#define SPI0_ENABLED 0
#endif
// <q> SPI0_USE_EASY_DMA  - Use EasyDMA
 

#ifndef SPI0_USE_EASY_DMA
#define SPI0_USE_EASY_DMA 0
#endif

// </e>

// <e> SPI1_ENABLED - Enable SPI1 instance
//==========================================================
#ifndef SPI1_ENABLED
#define SPI1_ENABLED 1
#endif
// <q> SPI1_USE_EASY_DMA  - Use EasyDMA
 

#ifndef SPI1_USE_EASY_DMA
#define SPI1_USE_EASY_DMA 1
#endif

☆2022年 4月4日(月) 午後 0時00分 初版(Ver1.00) 作成

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1