I2C and SPI on SAMD10D14A - Page 1
Forum section: electronics / general

author: anvoice
author_rank: Frequent Contributor
timestamp: March 23, 2018, 03:03:34 am
content: I'm trying to figure out the SPI and I2C interfaces on the SAMD10 chip, but my limited (Atmel 328P) experience is no help in determining some of the signals. From my understanding, SERCOM 0 and 1 are the I2C and SPI pins on the device, but I can't figure out which signal is clock, which is data for pads 0 and 1 for I2C, and similarly for the SDI, SDO, CLK and chip select for the SPI. Could anyone help with this, or point me to the place in the datasheet I need to read to figure that out?Depending on whether those coincide with the I2C, I was hoping to be able to talk to two slave devices, one using I2C and one using SPI, while sharing the clock and data pins and switching modes when needed. Specifically, I only need to configure one of the devices using SPI at startup, and then need to switch to I2C to continuously talk to the second device (an encoder).Finally, my uC will talk to an outside master controller via I2C: is it reasonable to use the same I2C pins as the ones I'm using to talk to the encoder to do that, or do I need to use the other SERCOM pins?

author: ataradov
author_rank: Super Contributor
timestamp: March 23, 2018, 03:14:16 am
content: Quote from: anvoice on March 23, 2018, 03:03:34 amSPI pins are configurable to a certain extent. Search for DIPO and DOPO in the datasheet and you will see additional mapping of pads to corresponding pins. I2C pins are fixed to PAD0 and PAD1.You can find bare-metal examples of SPI and I2C masters herehttps://github.com/ataradov/dgw/tree/master/embeddedQuote from: anvoice on March 23, 2018, 03:03:34 amThere are too many possible permutations to tell if it is going to work or not. You will need a pen and a piece of paper for thatQuote from: anvoice on March 23, 2018, 03:03:34 amYes, sure. As long as you keep speed and length of the wires in check, you should be fine.

author: anvoice
author_rank: Frequent Contributor
timestamp: March 23, 2018, 03:58:57 am
content: Quote from: ataradov on March 23, 2018, 03:14:16 amThanks, much appreciated! The examples are extremely helpful.Quote from: ataradov on March 23, 2018, 03:14:16 amShouldn't it be as simple as using PAD0 for SDA and PAD1 for SCL in I2C, then turning around and using the PAD0 for MOSI, PAD1 for SCL, and pads 2-3 for MISO and chip enable in SPI? Assuming the SPI are configurable to that extent of course.Quote from: ataradov on March 23, 2018, 03:14:16 amMy main source of confusion is what happens when the uC is, say, talking to the encoder (it has constantly do that to maintain motor position) when the external controller decides to send a command of its own (e.g. move to a different position). How would the chip detect that event? Interrupt?My encoder actually has a PWM output for position as well as I2C interface: I'm now wondering whether it may be wise to use that instead, using up an extra pin and measuring the duty cycle of the PWM to see where the rotor is, but simplifying the overall I2C communication procedure.

author: ataradov
author_rank: Super Contributor
timestamp: March 23, 2018, 04:05:19 am
content: Quote from: anvoice on March 23, 2018, 03:58:57 amWell, I wrote this before I remembered that I2C is not all that configurable. Yes, this configuration is possible with DOPO=0, DIPO=2. And SS can be any pin at all, just use it as a GPIO. Don't use SERCOM's SS, it is a pain and not worth it.Quote from: anvoice on March 23, 2018, 03:58:57 amIn both I2C and SPI mater always initiates the transaction, so device can't accidentally start anything. The rest depends on the type of your devices and their capabilities.Quote from: anvoice on March 23, 2018, 03:58:57 amI2C will probably be more accurate.

author: anvoice
author_rank: Frequent Contributor
timestamp: March 23, 2018, 04:33:27 am
content: Quote from: ataradov on March 23, 2018, 04:05:19 amRight, but the uC would be both slave and master depending on whether it's being talked to by the external controller (uC is slave) or talking to the encoder (uC is master). So don't I need a way to switch the uC from master mode during normal operation to slave mode when the external controller contacts it?

author: ataradov
author_rank: Super Contributor
timestamp: March 23, 2018, 04:36:25 am
content: Quote from: anvoice on March 23, 2018, 04:33:27 amI missed that part. No, you can't do this with one SERCOM. You need to be a master or a slave, unless you have some clearly defined way to share the time between the two. But it will be a huge pain to debug, I would not even try to attempt it.

author: anvoice
author_rank: Frequent Contributor
timestamp: March 23, 2018, 04:45:51 am
content: Quote from: ataradov on March 23, 2018, 04:36:25 amOk, this might mean I'll have to use the SAMD21 instead, as I'm running out of pins for all the connections. But assuming I'm using 2 SERCOMs, it should be no problem to use one for I2C master with the encoder and the other as I2C slave with external controller at the same time, correct?

author: ataradov
author_rank: Super Contributor
timestamp: March 23, 2018, 04:53:22 am
content: Quote from: anvoice on March 23, 2018, 04:45:51 amDigiKey is selling some real cheap D21s at the moment, but it looks like they mostly have QFN packages left, all cheap TQFPs are gone.Quote from: anvoice on March 23, 2018, 04:45:51 amCorrect. SERCOMs are absolutely independent.

author: anvoice
author_rank: Frequent Contributor
timestamp: March 23, 2018, 05:09:20 am
content: Quote from: ataradov on March 23, 2018, 04:53:22 amMy motor gate driver is actually QFN, so I'll have to figure out a way to solder QFN packages onto my board anyway... For the prototype at least, if I ever do production runs I'd do reflow of course. Now on to figuring out how many total pins I'll need.Thanks for the clear explanations!Edit: ok, so I'd have to somehow solder the ground plane to, well, ground on the QFN version. So it looks like I need to either get the TQFP or use some amazingly creative trick to get that ground plane connected.

author: anvoice
author_rank: Frequent Contributor
timestamp: March 23, 2018, 06:17:09 am
content: Does anyone know if there is any functional difference between the SAMD21 with a ground plane thermal pad and the one without? Both of the versions I'm looking at seem to operate at up to 125C. The one without the thermal pads will certainly be easier to solder on, so I was thinking of going with that. Any issues to look out for though?

author: ataradov
author_rank: Super Contributor
timestamp: March 23, 2018, 06:19:13 am
content: No difference whatsoever. Those things can't dissipate enough heat to worry about that kind of stuff. I think the pad is mostly for mechanical purposes.

author: anvoice
author_rank: Frequent Contributor
timestamp: March 23, 2018, 06:33:02 am
content: Sounds good, I can get the QFN no-pad version then, should be possible to solder that on with a fine tip.

author: ataradov
author_rank: Super Contributor
timestamp: March 23, 2018, 06:35:01 am
content: Quote from: anvoice on March 23, 2018, 06:33:02 amBut QFN chips always have a pad. And it loos like TQFP never has a pad in case of D21.Although there is a note in the datasheet "Note: The exposed die attach pad is not connected electrically inside the device.". So it should be fine to not solder it.

author: anvoice
author_rank: Frequent Contributor
timestamp: March 23, 2018, 08:55:10 am
content: Quote from: ataradov on March 23, 2018, 06:35:01 amhttps://www.mouser.com/ProductDetail/556-ATSAMD21E16L-MFThat one has no pad in the picture. Could be wrong of course, there are errors on that website occasionally, but that it definitely looks like a genuine picture of a QFN package.Edit: Ok, looked at that photo more closely and it looks like they edited out the pad for some reason. So you're right, they always have a pad.I realized that it was my gate driver that has the thermal pad that must be connected to ground, so I'll have to figure out how to solder that on anyway.Quote from: ataradov on March 23, 2018, 06:35:01 amWhere did you find that note? I don't seem to see it in the Packaging Information section of the datasheet no matter how hard I look.

author: ataradov
author_rank: Super Contributor
timestamp: March 23, 2018, 03:44:16 pm
content: Quote from: anvoice on March 23, 2018, 08:55:10 amThey often just match package name to a corresponding picture in the database without actually checking all the features of a specific device.Quote from: anvoice on March 23, 2018, 08:55:10 amIt is in the Microchip version of the D21 datasheet, for example in the section "38.2.2 64 pin QFN".