0

Metro Express SPI Woes
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Metro Express SPI Woes

by Casey10110 on Sat Jul 14, 2018 9:23 pm

Hi guys,

I am trying to get this code to work, which is adapted from https://github.com/mengbishu/bmp/tree/4 ... c3c579186d:

Code: Select all | TOGGLE FULL SIZE
 /*!
  * file SPICountElevation.ino
  *
  * 将BMP388连接到Arduino的SPI接口上, 下载程序
  * elevation is calculated based on temperature and sea level pressure
  * 这个示例只能计算一个大概的海拔高度
  * 计算公式:
  * P=P0*(1-H/44300)^5.256
  * @n 打开 serial monitor, 查看海拔高度.
  *
  * Copyright   [DFRobot](http://www.dfrobot.com), 2016
  * Copyright   GNU Lesser General Public License
  *
  * version  V0.1
  * date  2018-5-29
  */
#include "DFRobot_BMP388.h"
#include "SPI.h"
#include "math.h"

/*创建一个spi接口的bmp388对象,spi的片选引脚为3*/
DFRobot_BMP388 bmp388(10);

void setup(){
  /*串口初始化*/
  Serial.begin(9600);
  /*bmp388初始化*/
  delay(2000);
  bmp388.begin();
}

void loop(){
  /*读取大气压,计算海拔*/
  float pressure = bmp388.readPressure();
  float elevation = 44330 * (1.0 - pow(pressure / 101325, 1.0/5.255)) * (1.0/0.3048);
  Serial.print("Elevation : ");
  Serial.println(elevation);
  delay(100);
}



I am able to use it no problem on an Arduino Uno with the same wiring as you see here:

Image

Any ideas what the issue could be? It seems to get hung up on SPI.begin() ... are there known issues with the Adafruit SPI library, default SPI settings and the Metro Express?

Thank you all!
Casey

Casey10110
 
Posts: 23
Joined: Tue May 10, 2016 9:48 am

Re: Metro Express SPI Woes

by adafruit_support_mike on Sun Jul 15, 2018 1:06 am

The Metro M0 Express doesn't have SPI on GPIO pins 10-13.

It uses a 32-bit microcontroller, so its pinout is only generally similar to the Arduino Uno. The SPI pins are on the 2x3 header at the end of the board:

https://learn.adafruit.com/adafruit-met ... on/pinouts

adafruit_support_mike
 
Posts: 52085
Joined: Thu Feb 11, 2010 2:51 pm

Re: Metro Express SPI Woes

by Casey10110 on Mon Jul 16, 2018 12:06 pm

I have the exact same issue when wired up as such:

Image

I notice it also crashes without anything wired up whatsoever. Any other ideas of things to try? I notice my board is different than the board pictured in the tutorial. Mine does not have the 1st pin marked for the SPI on the silkscreen. The code crashes when the object is created:

Code: Select all | TOGGLE FULL SIZE
DFRobot_BMP388 bmp388(10);

Casey10110
 
Posts: 23
Joined: Tue May 10, 2016 9:48 am

Re: Metro Express SPI Woes

by Casey10110 on Tue Jul 17, 2018 8:56 pm

Interestingly, I am getting the exact same problem when using I2C as well, traced down to the following code in sercom.cpp:

Code: Select all | TOGGLE FULL SIZE
//Wait both bits Software Reset from CTRLA and SYNCBUSY are equal to 0
  while(sercom->I2CM.CTRLA.bit.SWRST || sercom->I2CM.SYNCBUSY.bit.SWRST);


For SPI the portion of code it gets stuck in is:

Code: Select all | TOGGLE FULL SIZE
while(sercom->SPI.CTRLA.bit.SWRST || sercom->SPI.SYNCBUSY.bit.SWRST);



Can you offer any suggestions of what to look at next? Why is this not exiting the while loop in either case? Could this be a defect in the actual hardware?

Best,
Casey

Casey10110
 
Posts: 23
Joined: Tue May 10, 2016 9:48 am

Re: Metro Express SPI Woes

by adafruit_support_mike on Wed Jul 18, 2018 12:07 pm

The lines you posted above occur in the resetWire() and resetSPI(), and the bits in question should only be 1 while the SERCOM clock is syncing with the CPU clock, or while the SERCOM's registers are being reset to their default values.

It's unlikely that those bits are getting stuck due to a hardware issue.. the I2C and SPI interfaces would probably be useless if such a problem existed. I'm not sure why the code would halt there, but adding code like Serial.print() that talks to other parts of the chip might create a loop that doesn't let the SERCOM sync.

It looks like the code you're using was written for a combination of Arduino Uno, ESP8266, and RasPi though. Those are all different platforms from the SAMD51, so it's very possible that the code makes assumptions about the hardware that aren't valid on the new board.

adafruit_support_mike
 
Posts: 52085
Joined: Thu Feb 11, 2010 2:51 pm

Re: Metro Express SPI Woes

by Casey10110 on Wed Jul 18, 2018 11:46 pm

It looks like the shuttleboard for the BMP388 that I am using may now be defective, as I can't get it to work with the UNO anymore as well. Thank you for your help, I'll let you know how it goes when I get another one.

Casey10110
 
Posts: 23
Joined: Tue May 10, 2016 9:48 am

Please be positive and constructive with your questions and comments.