Feather BLE/BluefruitMicro LE Chip Select

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Frigby
 
Posts: 48
Joined: Wed Oct 07, 2015 9:16 am

Feather BLE/BluefruitMicro LE Chip Select

Post by Frigby »

Hi,

Sorry if this sounds basic but my knowledge of hardware is limited.

I'm trying to connect a hall effect sensor to a arduino feather BLE - though using my old Bluefruit Micro as test bed as it has all the pins soldered and is sitting in breadboard.

The board of the sensor has the following diagram
halleffect.png
halleffect.png (40.93 KiB) Viewed 657 times
I get that the SCK,MOSI and MISO pins should connect to the relevant pins of the bluefruit/feather. From what I researched the SDA/CSn - SS/ line is the chip select line. I read in another forum post that I can use any GPIO pin for that. The documentation for the sensor says "chip select-active low". So am I right in assuming that if I set whichever GPIO to LOW it will get data from that, and if I set it to HIGH it will not ?

The pinouts page of the bluefruit says
"You can also use the SCK/MOSI/MISO pins with an SPI device as long as it is on a Chip Select line and you disable it when you talk to the BLE module."

Both the feather and bluefruit use Pin 8 as bluefruit CS pin. So my methodology should be, when I need to get data from the sensor I set Pin 8 HIGH, whichever GPIO pin is connected to the SDA Low and when I want to use the bluetooth module I set pin 8 low and whichever GPIO pin is connected to the SDA of sensor low ?

I'm only using the sensor for stepper motor stop detection so I wont be constantly switching between the two, just at initial calibration phase.

Thanks.

Frigby

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Feather BLE/BluefruitMicro LE Chip Select

Post by adafruit_support_mike »

You're thinking in the right direction.

To trim out one source of confusion, the pinout in your diagram shows a chip that can use two different signal protocols: SPI and I2C.

When you use SPI to communicate with the chip, the pin names will be (reading left to right) CS, SCK, MOSI, and MISO. When you use I2C, the pin names will be SDA, SCL, A1, and A2.

Since you've already established that you're using SPI, you can ignore the I2C names. The pin you're asking about is just 'CS'.

A microcontroller speaking SPI uses the CS signal to select the device it wants to talk to. Each external device connected to MOSI, MISO, and SCK has its own CS pin, and each of those is connected to a different GPIO pin on the microcontroller. SCK is the clock signal that tells the devices when to read and write data. MOSI is Master-Out/Slave-In, and its voltage is controlled by the microcontroller. All the external devices just listen to SCK and MOSI. MISO is Master-In/Slave-Out, and is how the external devices send information back to the microcontroller.

When an SPI device's CS pin is high, the device ignores any signals on SCK and MOSI, and if it's well-behaved, it also puts its MISO pin in a high-impedance state so other devices can send that signal high and low. If it isn't well-behaved, it tries to hold MISO either high or low when CS is high, and plays electronic tug-of-war with any other device that wants to talk to the microcontroller.

When an SPI device's CS pin is low, it listens to signals on SCK and MOSI, and assumes that it has complete control over the MISO line so it can send data back to the microcontroller.

User avatar
Frigby
 
Posts: 48
Joined: Wed Oct 07, 2015 9:16 am

Re: Feather BLE/BluefruitMicro LE Chip Select

Post by Frigby »

Hi,

firstly, thanks for the very detailed answer.

Just to clarify, to switch the MOSI pins etc to select the sensor(for sake of this example lets say the SS(or is it called CS) of sensor is connected to pin 12) I set pin 12 to LOW and the same time I set pin 8(the ble CS pin) to HIGH ? Or do I have to wire pin 8 to a separate GPIO pin and set that pin to high ?

Thanks.

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Feather BLE/BluefruitMicro LE Chip Select

Post by adafruit_support_mike »

On the Feather you're using, the nRF51822 BLE module's CS pin is already wired to GPIO 8 on the microcontroller. That pin isn't broken out to the edge of the Feather, but the connection exists.

If you have another SPI device and have connected its CS pin to GPIO 12 on the Feather, pins 8 and 12 will be the ones you use to select the devices.

To use the BLE module, send pin 12 high, then send pin 8 low. Pin 12 will tell the external device to ignore the SPI bus, and pin 8 will tell the BLE module to read and write data on the SPI bus.

To use the external device, swap the signals.. send pin 8 high to disable the BLE module, and pin 12 low to enable the external device.

User avatar
Frigby
 
Posts: 48
Joined: Wed Oct 07, 2015 9:16 am

Re: Feather BLE/BluefruitMicro LE Chip Select

Post by Frigby »

Hi,

I've been trying to get this to work and may have discovered something. According to details I found about the boards

"The zero position can be programmed into the devices simply with a SPI (AS5048A) or I²C command (AS5048B)"

I have the AS5048B board(it's just what I thought was right when I ordered it). So I think that means I have to use i2C rather than SPI.

Does this means all the stuff I asked before is irrelevant. So instead of using the CS SCK MOSI and MISO pins I need to use the SDA and SCL pins on the bluefruit/feather instead ?

The image from the data sheet seems to show that no matter what system you use MOSI MISO and SCK pins of the microcontroller. Which has me even more confused.

Thanks.

User avatar
Frigby
 
Posts: 48
Joined: Wed Oct 07, 2015 9:16 am

Re: Feather BLE/BluefruitMicro LE Chip Select

Post by Frigby »

Hi,

further reading has shown me that the version I have is indeed i2c version. The data sheet says

"Either populated with an AS5048A with SPI or AS5048B with I2C interface."

I know I have the B version so it's i2c. Unfortunately the data sheet only shows connections for SPI(the image I linked in first post) so that's where my confusion arose.(maybe i2c connections are obvious). So I now have to ignore that diagram.

Another part of my confusion is that a lot of the wiring diagrams of stuff using i2C just seem to use analog pins for SCL and SDA, not the dedicated pins on an arduino.(for example this https://learn.adafruit.com/adafruit-mcp ... e?view=all).

So should I use the dedicated pins or not ?

Thanks.

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Feather BLE/BluefruitMicro LE Chip Select

Post by adafruit_support_mike »

If you have an I2C version, ignore the SPI names and connect SDA/SCL to the corresponding pins on the Feather.

You might also want to check the breakout's documentation to see if the A1 and A2 pins have pull-up or pull-down resistors.

Each I2C device has a 7-bit address, and the microcontroller uses that to tell the I2C bus what device should pay attention to the following commands. Many chips have pins you can connect to VCC or GND that will change the address (so you can connect more than one chip to the same microcontroller). Breakouts usually connect those pins high or low using resistors so the chip always starts with some default address, but you can still change the address by connecting the pin to the opposite voltage.

Our breakouts use pull-down resistors, for instance, so all the optional bits in the address will default to 0. You can set any of those bits to 1 by connecting a pin to VCC though.

User avatar
Frigby
 
Posts: 48
Joined: Wed Oct 07, 2015 9:16 am

Re: Feather BLE/BluefruitMicro LE Chip Select

Post by Frigby »

Hi,

thanks for reply. Do the SDA and SCL pins of the bluefruit le have to be pulled up via some kind of resistor ? On the feather page is says of the SDA and SCL pins

"There's no pull up on this pin by default so when using with I2C, you may need a 2.2K-10K pullup"

but nothing on the bluefruit LE page(I realise it's an older board but it's my development environment before final project using feather).

Thanks.

User avatar
jevada
 
Posts: 194
Joined: Fri Dec 15, 2017 5:29 am

Re: Feather BLE/BluefruitMicro LE Chip Select

Post by jevada »

Frigby wrote: Do the SDA and SCL pins of the bluefruit le have to be pulled up via some kind of resistor ?
I2C in general requires pull-ups on SDA and SCL (these are open drain or open collector configured). There are no pull-up resistors on the adafruit board, you must add them on your hardware if they aren't there already.

Now, I2C is available in 4 different speeds: standard (100 kHz), full (400 kHz), fast (1 MHz) and high speed (up to 4 MHz). The "best" pull-up value depends on the I2C speed, Vcc and bus capacitance. As a good rule of thumb, use 10 kOhm resistors for standard speed, 4.7 kOhm for full and 2.2 kOhm for the higher speeds (assuming there's only 1 I2C device on the bus and the bus itself is of reasonable design).

Locked
Please be positive and constructive with your questions and comments.

Return to “Feather - Adafruit's lightweight platform”