YouTube2Text

EECS 373 - Fall 2026 - Lecture 12: "Serial Buses: I2C and SPI" — Transcript

by Interactive Sensing and Computing Lab · 12,546 words · 1,819 segments · language en · Watch on YouTube

Full transcript

  1. 0:21All right.
  2. 0:24You guys hear me? Okay.
  3. 0:26>> Yeah. Good. Good. All right. Cool.
  4. 0:31All right. So, Professor Sample is out
  5. 0:33this week. So, I'm your substitute
  6. 0:35teacher. I was thinking maybe we just
  7. 0:37watch a movie if that's okay.
  8. 0:40All right. Uh, so we're going to be
  9. 0:42learning about spy today. Um,
  10. 0:45couple announcements. So, homework 5 is
  11. 0:48due tonight. Um, team registration, if
  12. 0:52you haven't done that already, I think a
  13. 0:54lot of you haven't done it. Um, just
  14. 0:56fill out that Google form with your
  15. 0:57teammates. uh do that by Wednesday. If
  16. 1:01you don't have a team already, please
  17. 1:03reach out to me or Professor Sample and
  18. 1:05we'll help you get on a team. Uh we
  19. 1:08don't want any stragglers. So maybe you
  20. 1:10can also come to me after the lecture
  21. 1:12and we can try and find everyone a team.
  22. 1:14Okay.
  23. 1:15Um after tonight, you have homework six
  24. 1:18and homework 7. Um and then after that,
  25. 1:21you're all done with homework and we'll
  26. 1:22go into the project phase and all your
  27. 1:24focus will be on that.
  28. 1:28So uh last week you talked about uh UART
  29. 1:32that was a serial interface. We are
  30. 1:35going to be talking about SPI. Today
  31. 1:37stands for serial peripheral interface.
  32. 1:40Um it's kind of the same idea where
  33. 1:43we're we're having some chips on a board
  34. 1:45talking to each other. Uh but they've
  35. 1:47implemented it slightly differently.
  36. 1:50So if you want to do some reading on how
  37. 1:52Spy works, you can go to the reference
  38. 1:55manual. For whatever reason, Infinine
  39. 1:57has decided to change the name of it.
  40. 2:00So, they call it synchronous serial
  41. 2:02channel in the manual. Um, they kind of
  42. 2:04do that with all of them. For some
  43. 2:05reason, they changed the name. Um, you
  44. 2:08can also go to that that ARM book that
  45. 2:10we always reference and you can look at
  46. 2:12chapter 22 to read up on this a little
  47. 2:14bit more.
  48. 2:17Okay, so here's kind of the overview of
  49. 2:19what SPY is. Um, it's a very common
  50. 2:23communication protocol. Um, a lot of you
  51. 2:26will probably interface with it during
  52. 2:28the project. Um, if you have a device
  53. 2:31that needs a lot of data, this is
  54. 2:34typically what you would see on that
  55. 2:35device. So, for instance, if I have an
  56. 2:38LCD and I have a lot of pixels on the
  57. 2:41LCD that are different colors, well, in
  58. 2:43order for me to refresh that display, I
  59. 2:46need to send it a lot of data. And spy
  60. 2:48happens to be a common protocol that
  61. 2:50those type of displays use. Um, it uses
  62. 2:54four wires. Um, it's used for chip to
  63. 2:57chip communication. So, with like USB,
  64. 3:00that's more like device to device. Uh,
  65. 3:03spy is more like all on the same board.
  66. 3:06Um, and it has a single controller with
  67. 3:08multiple peripherals. So, if we think
  68. 3:11back to UART, that was just one to one,
  69. 3:14right? Only one device could talk to
  70. 3:15another device. We couldn't add more of
  71. 3:17those or more devices onto that bus.
  72. 3:20With Spy, we can actually add more and
  73. 3:22more devices and we can share the same
  74. 3:24wires between all those devices. And so
  75. 3:27it can kind of help out with if we're
  76. 3:29limited on how many pins are on our
  77. 3:32microcontroller. Um, that can help out
  78. 3:34uh cuz we're reusing those pins for
  79. 3:37multiple devices.
  80. 3:39Um, and it's synchronized. So what that
  81. 3:42means is it uses a clock. So, if you
  82. 3:44think back to UART, that had no clock
  83. 3:47wire on it. Um, you had to have the two
  84. 3:50devices basically speak at the same
  85. 3:53speed, right? We had a preconfigured
  86. 3:55baud rate for UART and you had to make
  87. 3:57sure that both devices were at that baud
  88. 3:59rate for them to talk to each other.
  89. 4:01With Spy, that's not how it works. With
  90. 4:03Spy, we have a separate clock uh wire
  91. 4:06which is driven by the controller. And
  92. 4:09so it can basically decide what the
  93. 4:11speed is going to be with that
  94. 4:12additional wire. Um it's full duplex
  95. 4:16with that which that means is we can
  96. 4:18both send and receive data at the same
  97. 4:20time very similar to UART. Um and it can
  98. 4:23go quite fast. So multiple megabits per
  99. 4:26second and it's a de facto standard. So
  100. 4:29I think Philips back in the 80s came up
  101. 4:31with this but there's no like standard
  102. 4:34document um that explains how this all
  103. 4:36works. the industry has just kind of uh
  104. 4:39figured out or all agreed on how this
  105. 4:42should work and a lot of devices out
  106. 4:44there all kind of speak this. Uh there
  107. 4:46are some differences between
  108. 4:48manufacturer to manufacture and we'll
  109. 4:49talk about what those potential
  110. 4:51differences are but most of the stuff
  111. 4:53that we're going to be talking about
  112. 4:54everyone has already kind of agreed on
  113. 4:55and this is how we implement spy. Okay,
  114. 4:59any questions so far?
  115. 5:02Okay,
  116. 5:06so here's an example where we have uh a
  117. 5:09controller. So this would most likely be
  118. 5:11our microcontroller. And then we have
  119. 5:13three peripherals. And you can see that
  120. 5:15they're all sharing those wires, right?
  121. 5:17Like I was talking about.
  122. 5:20And so those wires are SDO, that's
  123. 5:22serial data out, SDI, serial data in.
  124. 5:25And so the serial data data out of the
  125. 5:28controller will connect to the serial
  126. 5:30data in of the peripheral. and vice
  127. 5:32versa for the other way around. And then
  128. 5:34we have a clock like I was talking about
  129. 5:37and that's driven by the controller. So
  130. 5:40the controller is the one that actually
  131. 5:42flips the clock high and low, the
  132. 5:44peripheral does not touch that wire. It
  133. 5:46just listens to it. Um, and what that
  134. 5:50basically means is if we want to clock
  135. 5:52in data from the peripheral uh to the
  136. 5:55controller, well, the peripheral can't
  137. 5:57just start sending data. it needs to
  138. 5:59wait for the controller to actually
  139. 6:01start cycling the clock before it can
  140. 6:03send data.
  141. 6:08Okay, you'll notice that we have a
  142. 6:10couple more pins in here and they're
  143. 6:12called chip selects or CX. And so this
  144. 6:15is how we can uh do arbitration where
  145. 6:19the controller can choose who it wants
  146. 6:20to talk to. So because we're sharing all
  147. 6:23those data lines, we need some way to
  148. 6:25choose which device that we want to talk
  149. 6:28to. So how we do that is basically the
  150. 6:31controller would set the CS pin low. So
  151. 6:34if we were trying to talk to peripheral
  152. 6:362, it would set CS2 to low. It would
  153. 6:39keep CS1 and CS uh 3 high. And then it
  154. 6:43would talk to peripheral 2. Okay? And
  155. 6:46the other peripherals, they would see
  156. 6:48all that all that stuff happening on the
  157. 6:50bus. they would see the clock going and
  158. 6:51all that. They just won't listen to it
  159. 6:53because their chip select is high at
  160. 6:55that point. Does that make sense? Any
  161. 6:59questions so far?
  162. 7:02All right. And a good way to think about
  163. 7:05um spy is basically we have a shift
  164. 7:08register on the controller and a shift
  165. 7:09register on the peripheral and we're
  166. 7:11shifting data uh from the controller
  167. 7:14onto the peripheral and shifting data
  168. 7:16back from the peripheral to the
  169. 7:18controller. And to demonstrate that a
  170. 7:20little bit more, here's kind of an
  171. 7:22example.
  172. 7:24So here, as the clock goes up and down,
  173. 7:27we're going to take bit by bit, you
  174. 7:29know, on those STO and SPI lines, and
  175. 7:32we're going to take the data that was in
  176. 7:33the spy controller shift register and
  177. 7:36shift it over to the spy peripheral
  178. 7:39uh shift uh register. And then at the
  179. 7:42same time, we're also taking from the
  180. 7:43peripheral to the controller. Okay. And
  181. 7:46so you can implement this protocol with
  182. 7:48just two shift registers and a clock and
  183. 7:51you got spy. So this is kind of a good
  184. 7:54way to think about this how it actually
  185. 7:56gets implemented on your
  186. 7:58microcontroller. Um we don't know uh we
  187. 8:01think we have some ideas but this is
  188. 8:04just kind of just to demonstrate um how
  189. 8:06this could work.
  190. 8:08Okay. The packet sizes they're typically
  191. 8:108 bits but this isn't standardized. you
  192. 8:13know, it's one of those things that's
  193. 8:14not standardized. So, the device and the
  194. 8:18controller would have to agree on how
  195. 8:19big the packet sizes are going to be.
  196. 8:22Um, so typically those are between 4 and
  197. 8:2416 16 bits, but mostly 8 bits is the
  198. 8:27go-to. And there's no flow control. So,
  199. 8:29UART has some flow control. And then
  200. 8:32we're going to be talking about I
  201. 8:33squared C next. It has something called
  202. 8:35an acknowledgement bit. There's no
  203. 8:37acknowledgement for spy. Um, if you
  204. 8:40wanted to implement something like that,
  205. 8:42you could probably do it in software.
  206. 8:44Uh, but there's no like mechanism built
  207. 8:46into the spy protocol to do that type of
  208. 8:48stuff.
  209. 8:50Okay. Any any questions on this part?
  210. 8:54Still all making sense?
  211. 8:57This is my first time lecturing, so Oh,
  212. 8:59you got a question. So does
  213. 9:08>> um it depends on how the peripheral is
  214. 9:10designed. But yes, that's that's uh how
  215. 9:13you should think about this part. Yeah.
  216. 9:18>> If you want to receive data, you have to
  217. 9:19send data basically. So most of the time
  218. 9:22we'll see in an example where you don't
  219. 9:24necessarily need to send data, but the
  220. 9:27the line has to be high or low. So
  221. 9:29technically you are either sending all
  222. 9:31ones or sending all zeros. So yes, you
  223. 9:33would be sending data even though it
  224. 9:35doesn't really look like you are.
  225. 9:37>> Uh you first. Yeah.
  226. 9:38>> Yeah. Um also you're saying that there
  227. 9:42is a [clears throat] single register
  228. 9:44where
  229. 9:48[snorts]
  230. 9:498 bit.
  231. 9:54>> So we we're going to we have a
  232. 9:55falsestead simulation that I'm going to
  233. 9:57show right after this. Maybe hopefully
  234. 9:59that'll answer your question. If it
  235. 10:00doesn't let me know and we'll we'll
  236. 10:01we'll circle back. You had a question?
  237. 10:03Um let's say like like you said if I
  238. 10:07want to read something from I need to
  239. 10:10write something as well.
  240. 10:12>> Does that mean my has to have like know
  241. 10:14like this means nothing?
  242. 10:17>> So yes the you would beforehand kind of
  243. 10:20figure out how the controller and the
  244. 10:23peripheral would talk to each other. Um
  245. 10:25I'm just going to skip ahead a little
  246. 10:26bit to kind of explain what the typical
  247. 10:29transaction would look like.
  248. 10:32Okay, here we go. This is what you're
  249. 10:34typically going to see. So, you don't
  250. 10:37necessarily see both data being
  251. 10:39transmitted and received at the same
  252. 10:41time. So, we got the SDO, that's what's
  253. 10:44being sent from the controller to the
  254. 10:45peripheral and the SDI, that's what the
  255. 10:48peripheral is sending to the controller.
  256. 10:50You can see in this example, it's it's
  257. 10:53one after another, right? We're first
  258. 10:55sending data from the from the
  259. 10:57controller and then we're sending data
  260. 10:59from the peripheral. Okay? Okay. And the
  261. 11:01reason you would probably do this is
  262. 11:03because the controller probably needs to
  263. 11:05request from the peripheral which what
  264. 11:07data do I actually want? Okay. So this
  265. 11:11transaction might be like the controller
  266. 11:13might want to read register S on the
  267. 11:17peripheral. Okay. So usually other
  268. 11:19devices other peripherals will have like
  269. 11:21internal registers. Uh so maybe it wants
  270. 11:24to read uh uh register S and then F
  271. 11:28would be the data that the peripheral
  272. 11:30sent back uh that was in its register.
  273. 11:34Okay,
  274. 11:36any other questions?
  275. 11:39All right, so let's kind of look at that
  276. 11:41false said.
  277. 11:44Um
  278. 11:45I think I have it here.
  279. 11:48Okay, so in this example, we don't have
  280. 11:51the the return path. So the peripheral
  281. 11:54going back to the controller. We're just
  282. 11:55kind of showing how if the controller
  283. 11:57wanted to send data through the
  284. 11:59peripheral, this is what it's going to
  285. 12:00look like. You can see we have two shift
  286. 12:03registers. We got uh the shift register
  287. 12:06for the controller right here, and we
  288. 12:08got the shift register for the
  289. 12:10peripheral here. You can see this is the
  290. 12:12data that we currently have in the
  291. 12:14controller's shift register. We got a
  292. 12:17clock in here. This clock will go to
  293. 12:20both peripherals. And then we have these
  294. 12:23lines here. These are our chip selects.
  295. 12:25So right now I have chip select one low.
  296. 12:29And low means I want to select you. So
  297. 12:32if we if we run this simulation, what we
  298. 12:34should see happen is the data in this
  299. 12:36shift register should get shifted over
  300. 12:39on this wire to this peripheral for each
  301. 12:42clock edge. Okay. So, let's just kind of
  302. 12:44run that and hopefully that will make
  303. 12:46sense to you guys.
  304. 12:49So, there's the clock going. You can see
  305. 12:51the clock down here is clocking
  306. 12:54and it's not shifting.
  307. 12:57So, I have to actually tell it to shift.
  308. 12:59So, let's try that one more time.
  309. 13:05Okay, now it's shifting the data. You
  310. 13:07can see here's the data that's being
  311. 13:09sent [clears throat] on the SDO line
  312. 13:11through the peripheral.
  313. 13:13And when we're done with those eight
  314. 13:14bits, we should see the same data that
  315. 13:18was in this shift register now got
  316. 13:20shifted over into this shift register.
  317. 13:24Does that make sense?
  318. 13:27Does that answer your question earlier,
  319. 13:28do you think?
  320. 13:30>> Uh, yeah. So, it's just one pack at a
  321. 13:32time.
  322. 13:33>> Yeah, one packet at a time. Okay. If we
  323. 13:36wanted to have some data on the
  324. 13:40peripheral that gets shifted back to the
  325. 13:42controller, we could have done that. We
  326. 13:43could have had data there and had a wire
  327. 13:45coming back the other way and it would
  328. 13:47have filled in the side controller shift
  329. 13:49register with whatever data was in that
  330. 13:50other one.
  331. 13:52Okay.
  332. 13:55All right.
  333. 13:57So, why don't we go back to this?
  334. 14:05Okay, so here's a typical timing
  335. 14:06diagram. This will be like eight bits.
  336. 14:09You can see our clock. You can see our
  337. 14:11chip select that's going low during the
  338. 14:14transaction.
  339. 14:17Uh here's our serial data out. This is
  340. 14:19the data being sent by the controller. A
  341. 14:21serial data out could also come from the
  342. 14:23peripheral. That's what the pin is
  343. 14:25labeled for the out pin on both devices.
  344. 14:27So you just have to think about that.
  345. 14:28Similar to UR, right? You had a TX go to
  346. 14:31RX, TX go to RX. Same thing here. But
  347. 14:34here we'll assume this is coming from
  348. 14:36the controller. This is coming from the
  349. 14:39peripheral.
  350. 14:40And then there's our clock edges that
  351. 14:42we're using to shift in the data. And so
  352. 14:45we'll find on the next slide that we can
  353. 14:47actually choose which edge we want to
  354. 14:49use. But in this example, for each
  355. 14:51rising edge, the data that is in uh or
  356. 14:55is on those wires, that's the data
  357. 14:57that's being sent.
  358. 15:00This part make sense?
  359. 15:03All right.
  360. 15:05Okay. So, this is what I was talking
  361. 15:07about where we can choose actually what
  362. 15:09edge we want the data to actually get
  363. 15:12clocked in at. Um, so kind of confusing,
  364. 15:16but they split it into two things. They
  365. 15:18split it into a polarity thing and they
  366. 15:21split it into a phase. So, the clock
  367. 15:23polarity is basically what does the
  368. 15:26clock default as? Does it default at
  369. 15:29high or low? And so when there's no
  370. 15:31transaction going on, if I set the clock
  371. 15:34polarity to one, then this would be
  372. 15:36high. If the clock polarity is zero, it
  373. 15:39would be low. And then the phase, that's
  374. 15:41to choose whether or not we're clocking
  375. 15:43on the first clock edge or the second
  376. 15:46clock edge. Okay? So the phase of zero,
  377. 15:49that's going to be the first edge. Phase
  378. 15:51of one is going to be on the second
  379. 15:52edge. It doesn't necessarily mean
  380. 15:54whether it's going to be a rising edge
  381. 15:55or a falling edge. It's just whether
  382. 15:57it's the first or the second. Okay, does
  383. 16:00that kind of make sense?
  384. 16:04This this right here shows us all those
  385. 16:07different all the different combination
  386. 16:08of those four different modes. So we
  387. 16:11have modes 1 2 3 uh 0 1 2 3 and you can
  388. 16:16just kind of see how I can kind of show
  389. 16:18it with my cursor.
  390. 16:21So if the polarity is low, you can see
  391. 16:23it starts low and if the phase is zero,
  392. 16:26then we're clocking on the first edge
  393. 16:28here.
  394. 16:29If the phase is one, that means we're
  395. 16:31clocking on the second edge. And then
  396. 16:33here are the other combinations of that.
  397. 16:36Okay? And this is something that um
  398. 16:40wasn't standardized, right? So people
  399. 16:44started making spy devices and some of
  400. 16:46them decided, okay, well, I'm going to
  401. 16:48implement it like this or I'm going to
  402. 16:50implement it like this. And so what has
  403. 16:52happened is microcontrollers have now
  404. 16:54needed to support all of these different
  405. 16:56modes. And it's just because there's no
  406. 16:58standard. I mean, one of these would
  407. 17:00have worked for everyone, but no one
  408. 17:01could really agree on how to do it. Um,
  409. 17:04so now this is some setting that you're
  410. 17:06going to have to set up in your
  411. 17:07microcontroller in order to make sure
  412. 17:09that these devices can talk to each
  413. 17:10other. Anyone have a Yeah, question.
  414. 17:14>> What's the difference between sampling
  415. 17:15and talking?
  416. 17:18>> Okay, toggling. Yeah, good question. So,
  417. 17:20sampling is when the data is valid.
  418. 17:22Okay, so you can see this is called an
  419. 17:24an eye diagram.
  420. 17:26um it looks like an eye like your eye
  421. 17:28here. Um so the edge of the eye that is
  422. 17:33when the data is uh transitioning. So
  423. 17:35that's your toggling edge. Okay? So this
  424. 17:38would be your toggling edge right here.
  425. 17:40And then when the data is valid this
  426. 17:43would be your sampling edge.
  427. 17:45That make sense? Okay. Any other any
  428. 17:49other questions?
  429. 17:54Okay. So, we kind of already went over
  430. 17:56this slide, but this is what a typical
  431. 17:59transaction would look like. You're
  432. 18:01probably going to send data and then
  433. 18:03receive data. It's uh uncommon for you
  434. 18:06to be sending and receiving at the same
  435. 18:08time, but the protocol totally supports
  436. 18:10it and you can do that. Um, if for
  437. 18:13instance, let's say we had a lot of data
  438. 18:15to send or receive, well, you could
  439. 18:17basically say this transaction could be
  440. 18:19asking for data and then this
  441. 18:21transaction could be the receiving data
  442. 18:23of this transaction. But at the same
  443. 18:25time, we could be queuing up maybe the
  444. 18:27next read we're going to do. So you
  445. 18:28could do a bunch of sequential reads
  446. 18:30where we ceue them all up. That is
  447. 18:32potentially something that you could do
  448. 18:33with this. Okay, we can kind of figure
  449. 18:37out looking at this. Um, all right, we
  450. 18:40look at the clock. So the clock um by
  451. 18:43default is high. So that means that the
  452. 18:46polarity is one. And we we can see that
  453. 18:49we're sampling the [clears throat] data
  454. 18:51on the second clock edge. So that means
  455. 18:53that our phase is uh one as well. So
  456. 18:56this would be mode three.
  457. 19:01All right. So there are there's no
  458. 19:03maximum speed that spy can go. It's
  459. 19:06really dependent on your hardware. Um if
  460. 19:08your wires can handle the speed and your
  461. 19:10peripheral can handle the speed, then
  462. 19:13the microcontroller can go as fast as it
  463. 19:16can.
  464. 19:17um [cough]
  465. 19:18[clears throat]
  466. 19:19the limits are so so the microcontroller
  467. 19:23it will be driving for instance the
  468. 19:24clock high and low okay we'll learn
  469. 19:27about for I squared C that that's not
  470. 19:30always the the case we have something
  471. 19:32called open drain uh we'll explain that
  472. 19:34later but that might be a little bit
  473. 19:36slower but in this scenario just like
  474. 19:38when you set up in lab one where you had
  475. 19:40the GPIO pin uh push pull that's what
  476. 19:43that means right I can drive the pin
  477. 19:45high or I can drive the pin
  478. 19:47And so however strong that drive circuit
  479. 19:49is and however uh much capacitance is on
  480. 19:53the bud on the bus that determines how
  481. 19:56fast we can go. Okay? You're going to
  482. 19:58have some parasitic capacitance on the
  483. 20:01bus. Wires have capacitance. Pins have
  484. 20:04capacitance. That's going to slow us
  485. 20:06down a little bit, but it's not that
  486. 20:07much. So that's kind of what determines
  487. 20:10our speed. you get really fast and then
  488. 20:13you start having reflections of the
  489. 20:15signals and things like that. Um, we
  490. 20:18probably won't go that fast in this
  491. 20:19class. Uh, but that is something you
  492. 20:21might have to worry about if you're
  493. 20:22getting into like some really high speed
  494. 20:24stuff.
  495. 20:26Um, as far as knowing how fast the
  496. 20:29peripheral can go, just read the data
  497. 20:31sheet and it'll hopefully tell you like,
  498. 20:33hey, this is how fast this device can
  499. 20:35actually consume data. And so if we read
  500. 20:39that data sheet, we'll see, okay, well,
  501. 20:41I'm going to set my spy clock to 1
  502. 20:43megabit because that's what my
  503. 20:46peripheral can handle. Sometimes you can
  504. 20:48actually overclock. Um, a lot of the
  505. 20:50times, like going back to the example of
  506. 20:52using a um LCD display for the projects,
  507. 20:56I think the specs say it can go up to
  508. 20:58like 10 megabits per second, but often
  509. 21:01we'll have groups overclocking to like
  510. 21:0430 40 and it still works fine.
  511. 21:07Okay,
  512. 21:10here are some standard speeds that you
  513. 21:12might see around, but like I said, you
  514. 21:15can really pick whatever clock frequency
  515. 21:17you want. There's no This is standard
  516. 21:20um which means sometimes you'll see them
  517. 21:23use these. Sometimes you'll even see up
  518. 21:25to 100 megabits per second. So you there
  519. 21:28are some high-speed spy u buses out
  520. 21:30there.
  521. 21:33Okay. So, one downside with having the
  522. 21:37controller always have to request data
  523. 21:41is that if the peripheral has some
  524. 21:43information or it has something
  525. 21:45important it needs to uh tell it to the
  526. 21:47controller, there's really no way for
  527. 21:49the peripheral to get the controller's
  528. 21:51attention. Like um something happens,
  529. 21:54hey controller, I have data center.
  530. 21:55There's really no way to do that. So, we
  531. 21:57have to go outside of the spec. we have
  532. 21:59to go outside of spy and we have to
  533. 22:01implement that in some other way. And so
  534. 22:03in this example, what we're doing is
  535. 22:05we're adding some more wires. So if we
  536. 22:07can afford it, we'll add a couple more
  537. 22:09wires and we can use those wires as
  538. 22:11signals to our controller like, hey, I
  539. 22:13have something important to tell you,
  540. 22:15can you please wake up and let me clock
  541. 22:17in data to you? Okay. So, an example for
  542. 22:20this would be let's say I have a
  543. 22:23smartwatch and I most of the time want
  544. 22:26the screen to be off to not waste
  545. 22:28battery, but when I lift up that
  546. 22:30smartwatch to my face, I want the screen
  547. 22:32to turn on. Okay? And the way that we
  548. 22:35detect that is we have some gyro that's
  549. 22:37kind of measuring that movement and
  550. 22:39figuring out when the watch has been
  551. 22:42risen up. And if we were to just have
  552. 22:45the microcontroller uh just use regular
  553. 22:48spy to talk to the gyro, the potential
  554. 22:50issue is that um basically we have to
  555. 22:53constantly pull that gyro and we might
  556. 22:56want the microcontroller to go to sleep,
  557. 22:58right? If we want the screen off, we
  558. 23:00want it we want the watch to have a long
  559. 23:02battery life. Kind of want everything to
  560. 23:03be like in a low power mode. So what we
  561. 23:06could do and this is very common on
  562. 23:08gyros is we can use one of the interrupt
  563. 23:10pins that they usually have built into
  564. 23:12them. And so there will be some logic
  565. 23:14running on the gyro. It will detect this
  566. 23:16motion. It will flip one of those
  567. 23:19interrupt pins, maybe send a pulse or go
  568. 23:22high and that will tell our
  569. 23:23microcontroller like, "Hey, it's time to
  570. 23:25wake up. I got some important
  571. 23:27information to tell you." The
  572. 23:29microcontroller will read that data off
  573. 23:31the gyro. And then that is a way that we
  574. 23:34could save power in this type of um
  575. 23:36application. Okay. So there are ways to
  576. 23:40get around the issue of the controller
  577. 23:43um having to initiate every single
  578. 23:45transaction.
  579. 23:47How are we doing so far?
  580. 23:50Any questions?
  581. 23:54All right.
  582. 23:57I was going to say earlier I've never
  583. 23:58lectured before. So the fact that you
  584. 24:00have questions is scary
  585. 24:03because I have a feeling I'm not doing
  586. 24:04that well. But anyways, let's keep
  587. 24:05going.
  588. 24:08All [snorts] right. So, what are we
  589. 24:10talking about here? Oh, okay. So, we
  590. 24:12talked about how these are shift
  591. 24:13registers. Well, that means that we
  592. 24:15could do something kind of clever. Um,
  593. 24:17and I'll kind of explain that. So, we
  594. 24:20could actually daisy chain uh
  595. 24:23peripherals. And basically what we could
  596. 24:25do is we could put the STO to the one
  597. 24:29peripheral and then daisy chain. So,
  598. 24:30have the out of the other peripheral go
  599. 24:32to the next one to the next one. And so
  600. 24:34what could happen as we're cycling that
  601. 24:36clock, all that data is just we
  602. 24:39basically made a ginormous uh chip
  603. 24:41register and we're just shifting that
  604. 24:43data all the way down through all the
  605. 24:44peripherals. And the advantage of this
  606. 24:47is I don't need a chip select for all
  607. 24:49those peripherals. So let's say I had an
  608. 24:53LED strip. Okay? And this is something
  609. 24:55you probably will interface with uh
  610. 24:57during the project. This thing has
  611. 24:59hundreds of LEDs on it, right? If I were
  612. 25:01to use Spy House design with the chip
  613. 25:05selects, that would mean I would need
  614. 25:06like a 100 wires going down that strip
  615. 25:09in order to select which LED I want to
  616. 25:12talk to. Um, and as far as talking to an
  617. 25:15LED, why would I want to talk to an LED?
  618. 25:17Well, if I want them all to be a
  619. 25:19different color, I basically need to
  620. 25:20program them. So, that would mean I
  621. 25:22would need to talk to each of them
  622. 25:23individually so they could they could
  623. 25:25all be different colors. And so, the
  624. 25:27data that I'm sending to them is
  625. 25:28basically my color data. This is a very
  626. 25:31common thing that you'd see. I'm sure
  627. 25:32you've seen the LED strips but maybe not
  628. 25:34understood how they work. So anyways,
  629. 25:37going back to that with the shift
  630. 25:38registers, I don't need a chip select
  631. 25:41for all those LEDs. Instead, what I can
  632. 25:43do is I can just shift out all of the
  633. 25:45data. So there's, let's say there's 100
  634. 25:46LEDs. I would do a 100 transactions. All
  635. 25:49that data would get shifted to all those
  636. 25:51different LEDs and then I would have
  637. 25:53some kind of trigger, maybe like a
  638. 25:55pause. Maybe I pause for a couple
  639. 25:57milliseconds and that would tell the
  640. 25:58LEDs, okay, whatever values currently in
  641. 26:01your shift register, this is the color
  642. 26:03that you should display. Okay, that's
  643. 26:06how something like this would work. Um,
  644. 26:08if we look at this timing diagram here,
  645. 26:11in this example, we have a U, U1, and
  646. 26:14U2. So uh the first transaction would be
  647. 26:17the data going to U2 and then for the
  648. 26:21next transaction the data uh between
  649. 26:26these two
  650. 26:28that's what we're seeing on the top
  651. 26:29line. The data between these two is what
  652. 26:32we're seeing on the bottom line. So the
  653. 26:34data that was here then gets shifted to
  654. 26:36this device. And then after those two
  655. 26:39transactions, the data that we needed
  656. 26:41for U1 is there and the data that we
  657. 26:43needed for U2 is there.
  658. 26:46Does that kind of make sense how this
  659. 26:47would be possible?
  660. 26:50How we could daisy chain those all
  661. 26:51together?
  662. 26:55Okay, [snorts]
  663. 26:57any questions?
  664. 27:00All right.
  665. 27:04Okay, we're going pretty quickly.
  666. 27:07Um, okay. Spy on the XMC 4700. So, I
  667. 27:13think we learned about in UART that
  668. 27:16there's these things that are uh these
  669. 27:18channels that are configurable on our
  670. 27:20device. So, the device we use in lab and
  671. 27:23there's six of them. They call them
  672. 27:24USIC. I forget what universal serial
  673. 27:27something. Forget what it stands for.
  674. 27:30Um, anyways, there's six of them. We can
  675. 27:32configure them to be whatever we want.
  676. 27:33you want if they want you want them to
  677. 27:35be UART we can configure them to be UART
  678. 27:37if we want them to be spy we can do that
  679. 27:39we're going to learn about I squared C
  680. 27:40you could use them for that and the
  681. 27:42reason they did that is all of these
  682. 27:44protocols have similar things that can
  683. 27:46get reused they're all going to have
  684. 27:48like a clock they're all going to have
  685. 27:50buffers where data gets received and
  686. 27:53transmitted um so they decided to just
  687. 27:56reuse a lot of that hardware and just
  688. 27:58make these generic boxes that can talk
  689. 28:00all kinds of different protocols Okay.
  690. 28:04Um,
  691. 28:06again they call this synchronous serial
  692. 28:08channel on the XMC. And then this thing
  693. 28:11has uh these just for UART as well. They
  694. 28:14have uh FIFO buffers. So if you want to
  695. 28:17receive a lot of data pretty quickly,
  696. 28:19they have 64 of that or send a lot of
  697. 28:21data quickly. And then there's also some
  698. 28:23interrupts that these things can
  699. 28:24generate. Um, it also supports something
  700. 28:27called dual spy and quad spy. Um, so
  701. 28:32these are really common with flash chips
  702. 28:34that might be on your PCB. So let's say
  703. 28:37my microcontroller uh needs more flash
  704. 28:40and I decide to put a flash chip next to
  705. 28:42it. Uh, the way that I would interface
  706. 28:44with that is potentially these these
  707. 28:46things called dual spy or quad spy. And
  708. 28:49instead of having one wire that's
  709. 28:51transmitting data, how these things work
  710. 28:52is dual spy will have two wires. So,
  711. 28:55what that means is I can go twice as
  712. 28:57fast. Or if it's quad spy, that means I
  713. 28:59can go four times as fast. And that
  714. 29:01might be something I might want for
  715. 29:03flash because usually, you know, I want
  716. 29:06to get data on and off that flash as
  717. 29:07fast as possible. And so that's why a
  718. 29:10lot of the times they have this uh kind
  719. 29:12of it's a hybrid between a parallel
  720. 29:14interface and a serial interface because
  721. 29:17we're adding those additional channels
  722. 29:19uh that the data can be sent on. Okay.
  723. 29:24All right, so let's kind of go over what
  724. 29:26the pros and cons are of uh Spy. So the
  725. 29:31wiring is pretty straightforward. We
  726. 29:32have four wires. If we want to add more
  727. 29:35and more devices, that's going to cost
  728. 29:36us an additional wire. Okay, if we think
  729. 29:39back to UART, every time we added a new
  730. 29:42device, we had to add two more wires,
  731. 29:44right? And the other potential issue
  732. 29:47with UART is every time I add a device,
  733. 29:49I have to use another USIC channel.
  734. 29:52Okay. So, basically on my mic on the
  735. 29:54microcontroller we use, we're maxed out
  736. 29:56at six UART devices. With SPY, I can use
  737. 30:01I can use basically any GPIO pin for
  738. 30:03that chip select uh wire. And so, what
  739. 30:06that means is we're really limited by
  740. 30:08the number of pins on our device. So,
  741. 30:10for like the XMC 4700, it has 100
  742. 30:13something GPIOs. That means I could
  743. 30:16potentially have the spy set up where I
  744. 30:18have a 100 devices [clears throat] on
  745. 30:20that bus and they would all share the
  746. 30:22same clock and data lines.
  747. 30:24It is faster than asynchronous serial.
  748. 30:27So that clock is going to help us go a
  749. 30:29little bit faster. And there's no
  750. 30:31addressing. We'll talk about that in I
  751. 30:33squared C, but there's uh the only
  752. 30:36addressing that we really have are those
  753. 30:37chip select lines to let uh the
  754. 30:40peripherals know that they're being
  755. 30:41talked to. Um,
  756. 30:44chip select doesn't really scale that
  757. 30:46well. Let's say I have an Arduino like
  758. 30:48microcontroller. It only has like 15 IO
  759. 30:52pins. Well, that means that I can only
  760. 30:54have around 15 uh spy devices before I
  761. 30:58run out of pins.
  762. 31:00Um, there's no acknowledgement. We'll
  763. 31:02talk about with I squed C why an
  764. 31:03acknowledgement might be helpful. And
  765. 31:05there's no flow control like UART. And
  766. 31:08the controller must initiate all those
  767. 31:10communications. So with UR the whatever
  768. 31:13was on the um one end could always send
  769. 31:15data to the other one and vice versa.
  770. 31:18With spy the controller is the one that
  771. 31:20has to initiate all of those uh
  772. 31:23transactions.
  773. 31:26All right. So that is spy. Any last
  774. 31:29questions before I move on to I squ C?
  775. 31:34It all kind of makes sense.
  776. 31:38Okay.
  777. 31:46So, I squared C.
  778. 31:52So, it stands for interintegrated
  779. 31:55circuit. Um, everyone calls it I squ C
  780. 31:58though or I2C.
  781. 32:00Um, I I always forget what this actually
  782. 32:04called, but it's this is what's called
  783. 32:05inner integrated circuit. Um, you can
  784. 32:08read about it in the reference manual.
  785. 32:10Again, they kind of swat switched up
  786. 32:12what this thing is. It's called they
  787. 32:13call it interic bus protocol or IIC.
  788. 32:18Um, you can read about it here. This
  789. 32:20protocol was actually standardized at
  790. 32:22one point and um, NXP is the current uh,
  791. 32:26company that owns it. So, you can
  792. 32:28actually look up the spec for this
  793. 32:30protocol.
  794. 32:32All right. So, what is I squared C?
  795. 32:34Talked about how it's pronounced. It was
  796. 32:37developed also by Philips back in the
  797. 32:3980s for television sets. So they're
  798. 32:41they're uh designing TVs that had a
  799. 32:44bunch of IC's on them and they were
  800. 32:46trying to figure out ways to kind of
  801. 32:48reduce the number of pins that they
  802. 32:49needed and a way to communicate between
  803. 32:52all the different IC's on a TV.
  804. 32:55Um they had uh patents back when they
  805. 32:59invented this, but those patents have
  806. 33:01since expired. So now it's the de facto
  807. 33:04standard uh for two-wire communication.
  808. 33:07Um what that means is everyone well the
  809. 33:11the standards exist but now there's no
  810. 33:13license to use to use it. Um a lot of uh
  811. 33:17different companies have implemented it.
  812. 33:19Anytime you're going to have a simple
  813. 33:21sensor that doesn't have to send that
  814. 33:23much data like a temperature sensor or
  815. 33:25something like that um you're going to
  816. 33:27use I squared C. I suspect most of you
  817. 33:30for your project you're going to be
  818. 33:31using I squared C in lab this week we're
  819. 33:34going to be talking to an accelerometer
  820. 33:36via I squared C. So it's very common.
  821. 33:41Uh so 2 years ago and 2 days uh the
  822. 33:45patents expired. So that means you no
  823. 33:47longer have to pay NXP. So Phillips got
  824. 33:50spun into NXP. You no longer have to pay
  825. 33:54them in order to implement this
  826. 33:55protocol. But what they do still do is
  827. 33:58they keep a list of all the addresses
  828. 34:01that have been assigned to devices or
  829. 34:03sensors. Okay, we're going to learn
  830. 34:05about why this protocol needs addresses
  831. 34:08and why each uh peripheral needs its own
  832. 34:12uh unique address in order to make sure
  833. 34:14there's no conflicts. So devices have
  834. 34:17two devices having the same address.
  835. 34:19What NXP offers is basically getting
  836. 34:22officially assigned an address. So you
  837. 34:26would pay some money to NXP. They would
  838. 34:28give you an address and they would
  839. 34:30guarantee you that that address is not
  840. 34:33used by any other official I squared C
  841. 34:37um device. Okay? And they don't publish
  842. 34:39that list. If they did, it would be
  843. 34:41pretty easy to just pick an address uh
  844. 34:44that's not used. I'm sure someone can
  845. 34:46figure out all the addresses they've
  846. 34:48already kind of sent out. Uh but that's
  847. 34:50technically how it works. And I'm sure
  848. 34:51there's a lot of companies out there
  849. 34:53that are just making sensors and not
  850. 34:55actually going through that process to
  851. 34:56get the address.
  852. 35:00Okay, so this is what it looks like.
  853. 35:02This is what the bus looks like. And it
  854. 35:05only has two wires. And we can add as
  855. 35:08many devices as we want. And we still
  856. 35:10only have those two wires. There's no
  857. 35:12additional wires needed for more
  858. 35:13devices. And it has some weird stuff
  859. 35:16going on here. We got some external
  860. 35:18resistors. These are pull-up resistors
  861. 35:21and we need these in order for this bus
  862. 35:23to work. So, we'll kind of explain that
  863. 35:26in the next couple slides, but that is a
  864. 35:29a thing about this bus. And the two
  865. 35:31wires that we have, we have serial data
  866. 35:33line, SDA, is what you'll commonly see
  867. 35:36it uh listed as, and serial clock line,
  868. 35:39SDL. Okay, so we have a clock and a
  869. 35:41data. And you might wonder, well, how do
  870. 35:44I send data and receive data? Well, both
  871. 35:47of these lines can be controlled by both
  872. 35:49the controller and the peripheral. So,
  873. 35:51if the peripheral wants to send data to
  874. 35:53the controller, it can do it using this
  875. 35:55wire and the same going the other way
  876. 35:57around. Okay? And we'll we'll go in the
  877. 36:00next couple slides and explain how that
  878. 36:02actually works. Um, so how do we
  879. 36:05actually make sure that we're talking to
  880. 36:07the correct address or correct device?
  881. 36:09We have an address. So, we have a bunch
  882. 36:11of devices or peripherals on the bus.
  883. 36:14They need to have addresses so that we
  884. 36:16can tell all the devices on the bus who
  885. 36:18we're actually talking to. And those are
  886. 36:20typically seven bits, but you can also
  887. 36:22configure it so that they're 10 bits or
  888. 36:2416 bits, but seven is very common. Um,
  889. 36:29address zero, that's if I
  890. 36:30[clears throat] wanted to broadcast
  891. 36:31something to all the devices, I could
  892. 36:33just use the address zero for that.
  893. 36:37And then the speed is actually
  894. 36:40determined by these pull-up resistors
  895. 36:42that we have. Can anyone guess why the
  896. 36:46speed would be controlled by the it
  897. 36:49would be dependent on whatever the
  898. 36:51resistor value is? Any ideas? [snorts]
  899. 36:54To give you a little hint. So if these
  900. 36:57are pull-ups, then what are these
  901. 36:59devices doing? Well, they're just
  902. 37:02pulling the lines low. They're not
  903. 37:04actually setting a high value. That's
  904. 37:06the job of the resistor. So the resistor
  905. 37:09will transmit a one. And if we wanted to
  906. 37:11transmit a zero, then we would have the
  907. 37:14device pull that down. So with that
  908. 37:17information, any ideas why the resistor
  909. 37:20value
  910. 37:22would impact the speed of how this
  911. 37:24works?
  912. 37:26No one.
  913. 37:28It gets at that that parasitic
  914. 37:30capacitance that we were talking about
  915. 37:31with spy. So all wires and like the pins
  916. 37:36on our microcontroller, they have a
  917. 37:38small amount of capacitance. We call
  918. 37:40that parasitic capacitance. And that
  919. 37:43wasn't designed into the system. It's
  920. 37:45just inherently there. And so we have to
  921. 37:48deal with it. And the problem is is
  922. 37:50these pull-up resistors can't charge up
  923. 37:53all those parasitic capacitors fast
  924. 37:55enough. Okay? So if we have a a big
  925. 37:58resistor value, you know, we're going to
  926. 38:01create basically an RC circuit and it's
  927. 38:03going to take a long time to uh
  928. 38:06basically pull that line high by the the
  929. 38:09resistor is doing that. And so what we
  930. 38:12could do is we could have smaller values
  931. 38:14and that would cause the line to go high
  932. 38:16faster. Otherwise, we're waiting for
  933. 38:18that edge transition. the longer that
  934. 38:20edge transition is, the the shorter
  935. 38:23basically the uh the longer the clock
  936. 38:25period has to be in order for that to uh
  937. 38:28go high and low. Does that kind of make
  938. 38:30sense? We're going to do a false bed
  939. 38:33that kind of shows that a little bit
  940. 38:35more uh detail. Um so we'll we'll get
  941. 38:38there if it doesn't make sense right
  942. 38:40now. What does that kind of look like
  943. 38:43inside the devices? So we have these N
  944. 38:47losses and again if we think back to
  945. 38:51when we were configuring GPIO in lab one
  946. 38:54we could either configure it as in a
  947. 38:56pushpull mode or we could configure it
  948. 38:58in an open drain mode. And that's what
  949. 39:01this this mode is. Basically these N
  950. 39:03mosses are pulling the line low but we
  951. 39:06don't have a poss.
  952. 39:10The thing that's actually driving the
  953. 39:12pin high is this external resistor which
  954. 39:15is outside of the chip. [clears throat]
  955. 39:19Does that make sense?
  956. 39:22Because of that we actually need to uh
  957. 39:25also read what's going on uh from the
  958. 39:29same pin. So uh the controller for
  959. 39:32instance will be driving the pin low
  960. 39:35[snorts] but in order to see the data
  961. 39:36that the peripheral is sending it also
  962. 39:39needs to basically read from that pin so
  963. 39:41that that pin can go in both directions.
  964. 39:43So we can both write and read from that
  965. 39:47pin. Okay. The reason why we're doing
  966. 39:50this is if we were to have both of these
  967. 39:53devices push and pull. So if if the
  968. 39:56peripheral was pushing the the line
  969. 39:58high, like it was driving the line high,
  970. 40:00and the controller was driving the line
  971. 40:02low, well, you have a conflict there.
  972. 40:04One's trying to drive it high, one's
  973. 40:06trying to drive it low. You're going to
  974. 40:07have a lot of current going between
  975. 40:09those. You might break something. So
  976. 40:12this uh this architecture here allows us
  977. 40:14to basically put any value we want on
  978. 40:17the on the line and it won't break
  979. 40:19anything. So for instance if uh the
  980. 40:22peripheral wants to send a one and the
  981. 40:25controller wants to send a zero well the
  982. 40:27controller will be driving it to zero
  983. 40:29and that's will be the actual value on
  984. 40:32here but nothing will break right even
  985. 40:34though the peripheral is trying to send
  986. 40:35a one it doesn't really matter uh
  987. 40:38because nothing will break and the
  988. 40:40peripheral will actually see that like I
  989. 40:42was trying to send a one but I'm seeing
  990. 40:45a zero on the bus. We'll see how that
  991. 40:47that tool could actually be useful later
  992. 40:49on.
  993. 40:51Does that the physics of this kind of
  994. 40:52make sense?
  995. 40:54All right, let's dig into it a little
  996. 40:56bit more. First, I kind of want to show
  997. 40:58the advantage of this bus, what it looks
  998. 41:00like. Um,
  999. 41:02so this is typically what you're going
  1000. 41:04to see. You're going to see a bunch of
  1001. 41:05devices on the bus. You only need four
  1002. 41:07wires, really two. You need your clock
  1003. 41:10and your data, and we need power and
  1004. 41:12ground. you have those four wires to all
  1005. 41:14the devices and they can all talk to
  1006. 41:16each other. So all five of those devices
  1007. 41:18hopefully they all have a different
  1008. 41:20address. Okay, if they had the same
  1009. 41:22address then if I tried to talk to this
  1010. 41:24one and this one had the same address uh
  1011. 41:27these devices wouldn't they would both
  1012. 41:28think they're being talked to. In
  1013. 41:30reality we only talk to one. So ideally
  1014. 41:32you would configure or make sure that
  1015. 41:34all of these devices have different
  1016. 41:36addresses. Um, sometimes you'll have
  1017. 41:39that issue where you want to use, well,
  1018. 41:42let's say you want to use a sensor,
  1019. 41:44multiple sensors that are all the same.
  1020. 41:46Well, they're all going to have the same
  1021. 41:47address, right? Cuz the manufacturer is
  1022. 41:49going to basically say, "Okay, this
  1023. 41:51device has this address." So, if I want
  1024. 41:53to talk to multiples of that, then I'm
  1025. 41:56going to have an issue. Um, I could use
  1026. 41:58external expander chips that can help us
  1027. 42:01in this situation. So they have some
  1028. 42:03chips that basically break out one I
  1029. 42:05squared C bus and and make it into a
  1030. 42:07bunch. So I can talk to a bunch of
  1031. 42:09devices that have the same address. And
  1032. 42:11sometimes these devices will have a wire
  1033. 42:14on them or a pin rather that I can set
  1034. 42:17high or low and that will actually
  1035. 42:19change the the address of my device.
  1036. 42:22Okay. So and we're actually going to do
  1037. 42:24that in lab 6. So, we're going to have
  1038. 42:27you play around with an accelerometer,
  1039. 42:29and there is a pin that I can set either
  1040. 42:31high or low, and that will determine
  1041. 42:33what the address of the device is going
  1042. 42:35[cough] to be. [clears throat] So, I can
  1043. 42:36talk to two of those devices. I can set
  1044. 42:38the pin high on one of them, the pin low
  1045. 42:40on the other one. We'll have two
  1046. 42:42different addresses. I can talk to those
  1047. 42:44two devices separately.
  1048. 42:47Does that make sense?
  1049. 42:50Okay.
  1050. 42:53Um, as far as pull-ups, uh, a lot of the
  1051. 42:56times you're going to get these boards
  1052. 42:58that they're going to just automatically
  1053. 43:00put the pull-ups on there for you. So
  1054. 43:02that, for instance, in lab, we're going
  1055. 43:04to be working with an accelerometer that
  1056. 43:06already has the pull-ups built into it.
  1057. 43:08But if you were designing the PCB, you
  1058. 43:10would have to think about putting those
  1059. 43:11pull-ups on there in order for this bus
  1060. 43:14to work.
  1061. 43:17Okay, so let's look at falsestead.
  1062. 43:20Um,
  1063. 43:26so for this example, um, the clock is
  1064. 43:29just going to be going all the time.
  1065. 43:31That's not what would actually be
  1066. 43:33happening. Uh, the clock only goes per
  1067. 43:36transaction. In the next couple slides,
  1068. 43:38we'll kind of show you what a
  1069. 43:39transaction looks like, but this is
  1070. 43:41really just to demonstrate
  1071. 43:43um what's going on with that parasitic
  1072. 43:45capacitance and how those uh those end
  1073. 43:49mosses are pulling the lines low.
  1074. 43:53Okay, so
  1075. 43:55here I have my clock and this is just
  1076. 43:58going high and low. You can see while
  1077. 44:00we're also driving the clock, we're also
  1078. 44:02reading it. Okay. So, both devices are
  1079. 44:05reading that uh the the target or the
  1080. 44:09peripheral it can do something called
  1081. 44:11clock stretching. So, if it if for
  1082. 44:13instance it wanted to slow down uh a
  1083. 44:17transaction, it could actually keep the
  1084. 44:18clock low to let the controller know
  1085. 44:21like, hey, I need more time.
  1086. 44:23Um that's kind of a thing. Um but okay,
  1087. 44:27so if we wanted to send data, so here's
  1088. 44:29our data line. You can see here's our
  1089. 44:31our pull-up resistor.
  1090. 44:34And I'm going to just turn off this
  1091. 44:36parasitic capacitance for for right now.
  1092. 44:38So if I wanted to send data, our clock
  1093. 44:40is just going. What I can do is I can
  1094. 44:44turn on this end loss right here and I
  1095. 44:46can pull the line low. Okay? And so now
  1096. 44:48my controller is talking on that data
  1097. 44:51line. If the target wants to respond and
  1098. 44:54send some data back, it uses the same
  1099. 44:56wire and it pulls it down. Okay, so
  1100. 44:59here's the target sending data. So
  1101. 45:01here's the data that was sent by the
  1102. 45:03controller. Here's the data being sent
  1103. 45:06by uh the target. Okay, does that part
  1104. 45:10make sense?
  1105. 45:12So it's kind of a clever way to use one
  1106. 45:14wire to talk in two directions.
  1107. 45:17So if we turn on that parasitic
  1108. 45:18capacitance,
  1109. 45:21you can see that our clock is now not
  1110. 45:25shaped norm. It's not a square wave
  1111. 45:27anymore. It's got that that curved
  1112. 45:29rising edge. And if you were to hook up
  1113. 45:32this bus to an oscilloscope, you would
  1114. 45:34actually see that like this is what what
  1115. 45:36the I square C transactions actually
  1116. 45:38look like. You have that that rising
  1117. 45:40edge that's kind of curved off at the
  1118. 45:42end. Okay. If that capacitance
  1119. 45:47um where we're already maxed out on
  1120. 45:50that, so let me just show an example
  1121. 45:51where
  1122. 45:53let's say we have a different resistor
  1123. 45:55here. So, so we have a higher resistor.
  1124. 45:57So, a higher resistor means that we have
  1125. 45:59to go slower, right? So, it looks fine
  1126. 46:03now, but that's because our capacitance
  1127. 46:06is quite low. Let's say we have a lot of
  1128. 46:08devices. As we add more and more
  1129. 46:10devices, our capacitance is going to get
  1130. 46:13bigger and bigger. There's going to be
  1131. 46:14more parasitic capacitance because we're
  1132. 46:16going to have more wires. We're going to
  1133. 46:17have more pins. Okay? So if that
  1134. 46:21happens,
  1135. 46:23we we crank up that capacitance. You can
  1136. 46:25see this is what happens to our clock
  1137. 46:27signal. It doesn't actually have enough
  1138. 46:29time to get up to the high value.
  1139. 46:33Okay? And if it if if it doesn't get
  1140. 46:35high enough, that could be an issue,
  1141. 46:37right? Our our target won't even see the
  1142. 46:39clock cuz the target is just seeing
  1143. 46:41whether it's high or low. You can see uh
  1144. 46:45well, it's still working here. we must
  1145. 46:47be still at the threshold for this
  1146. 46:50inverter. Um, but potentially the
  1147. 46:53capacitance could be so high that this
  1148. 46:54won't get high enough. And so what we
  1149. 46:56can do is we can make that resistor
  1150. 47:00smaller.
  1151. 47:01We want to go faster or we have more
  1152. 47:04devices.
  1153. 47:06Okay. And that fixed that. Let's go
  1154. 47:08faster and see what happens there.
  1155. 47:12So I'm going to make my clock go a
  1156. 47:13little bit faster. Maybe like 300 hertz.
  1157. 47:18Okay, now we're going really fast.
  1158. 47:19Again, we have that same issue where the
  1159. 47:21clock is not getting up to the the high
  1160. 47:24value uh fast enough. And we'll go even
  1161. 47:28lower. We'll go even lower on this. So
  1162. 47:30maybe we'll do 200 ohms. And now look,
  1163. 47:35we we fix the clock.
  1164. 47:39Okay, does that kind of make sense? What
  1165. 47:41we're trying to show in this slide is
  1166. 47:44that um basically how those end Mosses
  1167. 47:47work and kind of the realities of
  1168. 47:51building this with the parasitic
  1169. 47:53capacitance and the pullup resistors
  1170. 47:55kind of the things we have to design
  1171. 47:57around in order to get this thing to
  1172. 47:58work.
  1173. 48:01Any questions?
  1174. 48:03Any other values you want me to plug in
  1175. 48:05there?
  1176. 48:08Okay.
  1177. 48:12So let's go back to the slides.
  1178. 48:20Okay,
  1179. 48:22so we were just kind of talking about
  1180. 48:23the the physical aspects of I squared C,
  1181. 48:27but this is what the actual timing
  1182. 48:28diagram looks like. And it's kind of
  1183. 48:31unique in that we're not using edges to
  1184. 48:33clock in data. The data is actually it's
  1185. 48:36in those those those uh rectangles. So
  1186. 48:39the data is valid when the S the clock
  1187. 48:43line is high. Okay. So this is the point
  1188. 48:46where that data is valid. Why do they
  1189. 48:48kind of do that? So you know we have
  1190. 48:51that long rising edge in order to uh
  1191. 48:54deal with that. Basically how this works
  1192. 48:57is
  1193. 48:58uh the clock is going to go low. That's
  1194. 49:01going to happen quite quickly. We can
  1195. 49:02pull the line the clock line low fast
  1196. 49:04because there's no resistance there. And
  1197. 49:07that's basically signaling to let's say
  1198. 49:10we have the target sending data.
  1199. 49:13So in that example, if the target is
  1200. 49:14sending data, it would see that clock
  1201. 49:16line go low. And that would basically
  1202. 49:19tell it, okay, now it's time for you to
  1203. 49:21transition the data line to whatever
  1204. 49:24value you want to put there. So that is
  1205. 49:26that transition there. And hopefully
  1206. 49:29that takes a short amount of time or uh
  1207. 49:33that happens before we get to this this
  1208. 49:35point right here. Okay. So that's giving
  1209. 49:37some time for that to happen. Then by
  1210. 49:40the time that this clock signal is high
  1211. 49:43right here, whatever data that's on the
  1212. 49:45data line, it should be valid. Okay. Um
  1213. 49:50so that that's how data is clocked in
  1214. 49:52and out. Uh the other thing to look at
  1215. 49:55are these start and stop conditions.
  1216. 49:58So to start off a transaction, what the
  1217. 50:01controller is going to do, and maybe I
  1218. 50:03didn't mention it by the way. Well, here
  1219. 50:04it is right now. uh the controller is
  1220. 50:07the one generating the clock. So similar
  1221. 50:09to spy, the clock is is always driven by
  1222. 50:12the controller.
  1223. 50:14Um so the controller is going to be the
  1224. 50:16one that's going to kick off this
  1225. 50:18transaction. What it's going to do is
  1226. 50:20it's going to pull the data line low and
  1227. 50:22then that's kind of a warning to the
  1228. 50:25peripheral like, hey, we're about to
  1229. 50:27start a transaction. It's going to wait
  1230. 50:30a little bit of time and then it's going
  1231. 50:32to start cycling the clock. Okay. Then
  1232. 50:35once we've sent all of our data, we are
  1233. 50:38going to uh do this stop sequence here
  1234. 50:41where it's the data is going to finish
  1235. 50:43uh low and then uh the clock is going to
  1236. 50:46stop and then this is going to go high
  1237. 50:48and then the bus by default just rests
  1238. 50:50at high for both wires.
  1239. 50:54Does that part make sense?
  1240. 50:55>> Yeah.
  1241. 50:56>> If the controller like how does the
  1242. 50:59control
  1243. 51:01center?
  1244. 51:01>> It's the same issue we have with spy.
  1245. 51:04you would need to pull it or use an
  1246. 51:06internet or uh internet interrupt pin to
  1247. 51:10basically communicate that to the
  1248. 51:12controller.
  1249. 51:14Okay.
  1250. 51:16Any other questions?
  1251. 51:20Okay.
  1252. 51:23Okay. So, uh this is what a full frame
  1253. 51:27looks like. So, this is a a complete
  1254. 51:29transaction. We hadn't really touched on
  1255. 51:31the addressing part. So this is showing
  1256. 51:33the addressing phase and then the data
  1257. 51:36phase.
  1258. 51:38So because [clears throat]
  1259. 51:40uh we need to because each device um
  1260. 51:44doesn't have like a chip select line,
  1261. 51:46right? We need to first tell the bus who
  1262. 51:48we're talking to. And that's what this
  1263. 51:50address stage is. This is where we're
  1264. 51:52going to communicate to the bus which
  1265. 51:55device do we want want to actually talk
  1266. 51:56to. In this example, we have seven u
  1267. 52:00seven bits. Okay, this is how we do
  1268. 52:03arbitration. So we have seven bits and
  1269. 52:05that's going to be our our address.
  1270. 52:09Um, so that gets sent first and you can
  1271. 52:12see that start condition that we were
  1272. 52:14talking about right there. And then we
  1273. 52:17have a read write bit. Okay. And this
  1274. 52:20tells the target whether or not we're
  1275. 52:22about to do a write transaction or a
  1276. 52:24read transaction.
  1277. 52:26Okay. So whatever follows this address
  1278. 52:29part is then either a write or a read
  1279. 52:32and that's determined by what this bit
  1280. 52:34is set to. And then we have this thing.
  1281. 52:38This is an acknowledgement.
  1282. 52:40Um
  1283. 52:42it's for short we call it an act. And if
  1284. 52:45it's a not acknowledged we call that a
  1285. 52:47knack. Okay. And an an act is
  1286. 52:51represented if the uh the line goes low.
  1287. 52:54And what's unique about this is these
  1288. 52:57first eight bits, these are going to be
  1289. 52:59sent by the controller. The act is sent
  1290. 53:03by the target. Okay? So inside this
  1291. 53:06transaction using the same wire, both
  1292. 53:09the controller and the target are
  1293. 53:12talking inside of here. Okay.
  1294. 53:16Why might we want to use or why might we
  1295. 53:19want to assign zero to app? Why do we
  1296. 53:22use zero instead of one?
  1297. 53:26Can anyone guess?
  1298. 53:28>> Yeah.
  1299. 53:32>> Always. So acknowledge it by just not
  1300. 53:36doing anything.
  1301. 53:36>> Exactly. Yeah. So the only way that we
  1302. 53:39can acknowledge the only thing that we
  1303. 53:40can actually do as a target or
  1304. 53:42controller is pull the line low. The
  1305. 53:45resistor is always pulling it high. So
  1306. 53:47if the target's not even there and uh if
  1307. 53:51it's not even there this line would stay
  1308. 53:53high. Okay. So we what we need to do is
  1309. 53:56we need to assign an acknowledgement to
  1310. 53:58zero and so that uh that target would
  1311. 54:01pull this low and that would tell the
  1312. 54:04controller like hey I've acknowledged
  1313. 54:06that you have sent me an address. And
  1314. 54:09what does that kind of acknowledgement
  1315. 54:11mean? It I mean that's basically what it
  1316. 54:13means. and says hey I have successfully
  1317. 54:16I am ready to either uh read or write
  1318. 54:19data okay that's what the target is
  1319. 54:21saying to the controller
  1320. 54:24um what else about this
  1321. 54:29yeah okay one like okay so when we're in
  1322. 54:33lab and we're trying to figure out
  1323. 54:35what's wrong with this you're going to
  1324. 54:36hook up I squ C to a logic analyzer to
  1325. 54:40kind of figure out what's going on with
  1326. 54:41the bus when it's not working Okay,
  1327. 54:43that's the first thing I'm I'm always
  1328. 54:44going to ask you to do if your I squed C
  1329. 54:47is not working. Well, we got to hook up
  1330. 54:49a logic analyzer and see what's actually
  1331. 54:50going on. So, you're going to see
  1332. 54:52something like this on the logic
  1333. 54:53analyzer and you're going to see that
  1334. 54:55act that active and if that act is
  1335. 54:58staying high, which means not
  1336. 55:00acknowledged, it could mean a couple
  1337. 55:01things. It could mean that our target is
  1338. 55:03not wired properly. So, it's not even
  1339. 55:06there. So, it can't acknowledge anything
  1340. 55:07and it's not wired correctly. Or it
  1341. 55:10could mean that your address is wrong.
  1342. 55:12If you put the wrong address in there,
  1343. 55:14well then of course the device is not
  1344. 55:16going to acknowledge that because you're
  1345. 55:17talking to someone else. Okay, so that
  1346. 55:20could be some scenarios where um like
  1347. 55:23when when you're actually working on
  1348. 55:24this in lab where you would see a knack
  1349. 55:26there. Okay, so after we've done this
  1350. 55:30whole address phase, that's when we
  1351. 55:32start moving on to the data. And this
  1352. 55:33would be either a read or a write
  1353. 55:35depending on this bit here. And then we
  1354. 55:37send the data. Um and we can actually
  1355. 55:40have this continue on. So if I wanted to
  1356. 55:42send a lot of data, I could have a bunch
  1357. 55:44of data after this. So a bunch of 8bit
  1358. 55:46transactions or I could read a bunch of
  1359. 55:49data. Okay. And here's [clears throat]
  1360. 55:52another acknowledgement I think. Do we
  1361. 55:54talk? We'll talk about Yeah, we'll talk
  1362. 55:56about it on the next slide, I think.
  1363. 56:00Maybe.
  1364. 56:03Yeah, we'll talk about in a little bit.
  1365. 56:04We'll talk about what that other act
  1366. 56:06does uh for the data phase.
  1367. 56:11Okay, this protocol allows us to have
  1368. 56:14multiple controllers. This isn't
  1369. 56:16something you do commonly, but it is
  1370. 56:19capable of doing it. And it and
  1371. 56:21accomplish this is that using what we
  1372. 56:23call a wired and so we've essentially
  1373. 56:26made an ANDgate with a wire. Uh what
  1374. 56:31that means is if both device we have two
  1375. 56:33devices sharing the same wire. If both
  1376. 56:36devices are sending a one then we would
  1377. 56:39see a one on the b on the bus. If one of
  1378. 56:41the devices is sending a zero it would
  1379. 56:43be zero. If the other device is sending
  1380. 56:45a zero it be zero. If they're both
  1381. 56:46sending zero it would be zero. So that's
  1382. 56:48an and um and so what that allows us to
  1383. 56:53do with multiple controllers. Uh if we
  1384. 56:55have a single controller, we don't
  1385. 56:57really have to worry about arbitration,
  1386. 56:58but we do have to worry about that with
  1387. 57:00multiple controllers because if they
  1388. 57:02both want to talk at the same time, we
  1389. 57:04need to decide who actually gets to
  1390. 57:07talk. Okay? And so they're both going to
  1391. 57:10start sending the data at the same time.
  1392. 57:14Uh but then we're going to have this
  1393. 57:16arbitration thing where whoever sends
  1394. 57:18the first zero is going to win. Okay?
  1395. 57:21Because it's a wired hand. Whoever sends
  1396. 57:23the first zero, it's going to be zero.
  1397. 57:26And the other device can see that. So if
  1398. 57:28one device is sending a zero and the
  1399. 57:30other one's sending a one, well, they're
  1400. 57:32also both reading the line at the same
  1401. 57:34time, that other device will see the the
  1402. 57:37zero and be like, "Okay, I lost. Someone
  1403. 57:40has a higher priority message." So what
  1404. 57:42that basically means is if I have a
  1405. 57:43lower address, uh, I have a higher
  1406. 57:46priority. And and if I have the same
  1407. 57:48address, let's say these both
  1408. 57:50controllers are talking to the same
  1409. 57:52target, they have the same address.
  1410. 57:54Well, then it would go to the read write
  1411. 57:55bit. So whoever is writing, I think
  1412. 57:58writing is zero, that one would win. And
  1413. 58:00if they're both trying to write, then it
  1414. 58:02would go to whoever whoever sends the
  1415. 58:03lowest data value. Okay, that's kind of
  1416. 58:06how this arbitration scheme would work.
  1417. 58:08Does that make sense how that would all
  1418. 58:10work?
  1419. 58:12It's not that common. I can't imagine
  1420. 58:15why anyone would want to do this for the
  1421. 58:17project, [clears throat] for instance.
  1422. 58:19Uh, but it does exist. [snorts] You can
  1423. 58:22do it.
  1424. 58:24All right. So, we kind of we were kind
  1425. 58:25of talking about what this stuff would
  1426. 58:27look like on an oscilloscope.
  1427. 58:28[clears throat]
  1428. 58:28This is a screenshot from an
  1429. 58:30oscilloscope. You can see that curved
  1430. 58:33edge on the rising edge. Okay. And here,
  1431. 58:36um, it's kind of surprising that it
  1432. 58:38works, but it does. It's not quite
  1433. 58:40getting to high, but we can see we're
  1434. 58:43getting acknowledgements. Um, so this
  1435. 58:45this is what a natural transaction would
  1436. 58:47look like um on an oscilloscope. And if
  1437. 58:51if it's if you're looking at the logic
  1438. 58:53analyzer and everything looks right, but
  1439. 58:56the but things are still not working,
  1440. 58:58then that's where you got to pull out
  1441. 59:00the oscilloscope and that will give you
  1442. 59:02more information. Right? This is kind of
  1443. 59:03like an analog issue, right? That that
  1444. 59:05that curved edge. We need to see that on
  1445. 59:09an oscilloscope to kind of debug this
  1446. 59:11bus even further. Okay. During like the
  1447. 59:14exam, we might give you one of these di
  1448. 59:17diagrams and you should be able to look
  1449. 59:19at these [clears throat] signals and be
  1450. 59:21able to basically all the all the
  1451. 59:22writing up top. You should be able to
  1452. 59:24fill that all in. You should be able to
  1453. 59:25see what we're doing here. Like we're
  1454. 59:27doing a right and then doing a read.
  1455. 59:30Okay.
  1456. 59:33Any questions on that? [snorts]
  1457. 59:39Okay, so we talked about that
  1458. 59:41acknowledgement at the end of the data.
  1459. 59:45Okay, and it can mean two different
  1460. 59:47things depending on whether we're
  1461. 59:48writing data or reading data. If we are
  1462. 59:51reading data, then the acknowledgement
  1463. 59:53is going to be sent uh by the
  1464. 59:55controller. That kind of makes sense.
  1465. 59:57Okay, so the target is going to be the
  1466. 59:59one that's sending the data and the
  1467. 1:00:01controller is going to be the one that's
  1468. 1:00:02acknowledging that. What an
  1469. 1:00:04acknowledgement means if I acknowledge
  1470. 1:00:07it means I would like to receive more
  1471. 1:00:09data after this. That's what an it
  1472. 1:00:11acknowledge means in this scenario. If
  1473. 1:00:13it's if you send a nap and not
  1474. 1:00:16acknowledge that means okay you sent me
  1475. 1:00:18enough data we're done with this
  1476. 1:00:19transaction. Uh that's it. If we are
  1477. 1:00:22doing a write
  1478. 1:00:25uh that's where the the target is the
  1479. 1:00:27one doing the acknowledgement. So the
  1480. 1:00:29controller is sending data. The target
  1481. 1:00:32is acknowledging that data. And what
  1482. 1:00:34that acknowledgement means is like, yes,
  1483. 1:00:37I see that you're sending data. I
  1484. 1:00:38understand this data. It makes sense to
  1485. 1:00:41me. It's acknowledged. And not
  1486. 1:00:42acknowledge is something's going wrong.
  1487. 1:00:44Uh I don't understand the data. Um it
  1488. 1:00:47didn't come through. We, you know, it
  1489. 1:00:49can mean all all kinds of different
  1490. 1:00:51things. But that's kind of what the the
  1491. 1:00:53knack and the act means depending on
  1492. 1:00:56whether it's a write or a read.
  1493. 1:00:59Make sense?
  1494. 1:01:05All right. What are we trying to convey
  1495. 1:01:07here?
  1496. 1:01:09Okay. So, yeah, we were doing a read and
  1497. 1:01:12then you can see that the controller, it
  1498. 1:01:15only wanted to read one bite. So, it
  1499. 1:01:17sent a knack at the end of that telling
  1500. 1:01:19the control or uh telling the [snorts]
  1501. 1:01:22uh peripheral or the target, hey, we're
  1502. 1:01:25done uh with this transaction.
  1503. 1:01:31Okay. So, just like uh spy,
  1504. 1:01:37we're going to be using and you are
  1505. 1:01:38we're going to be using those USIC
  1506. 1:01:40channels again.
  1507. 1:01:42Um, and this is what it kind of looks
  1508. 1:01:45like in the reference manual if you want
  1509. 1:01:47to see how this is set up. Um, our chip
  1510. 1:01:50does support multicontroller. So that
  1511. 1:01:52thing we talked about with the
  1512. 1:01:53arbitration scheme, our chip can
  1513. 1:01:56actually do that. Again, I don't know
  1514. 1:01:57why you would want to do that, but you
  1515. 1:01:58could if you wanted. And then target
  1516. 1:02:00mode. This is if you want the XMC to act
  1517. 1:02:05as a target, right? Um, so let's say I
  1518. 1:02:08have two uh microcontrollers and I want
  1519. 1:02:11one to be the controller, one to be the
  1520. 1:02:13target. I could set it up that way and
  1521. 1:02:15they could communicate to each other uh
  1522. 1:02:17via I squared C. So that is a a thing
  1523. 1:02:20that we can do. One weird thing about
  1524. 1:02:23the XMC 4700 is we can actually
  1525. 1:02:28uh choose a pin. So these are these
  1526. 1:02:31squares right here are pins. We could
  1527. 1:02:34actually use four pins instead of two
  1528. 1:02:36pins to talk I squed C. So we could have
  1529. 1:02:39one P pin be the the clock output and
  1530. 1:02:42one pin be the clock input. Usually you
  1531. 1:02:45want it set up like this where you're
  1532. 1:02:47using the same pin for both of those. If
  1533. 1:02:50you did this, you'd have to connect them
  1534. 1:02:51together outside of the chip. Um the
  1535. 1:02:55only reason I can really think of them
  1536. 1:02:56doing this is because this USIC is
  1537. 1:02:59designed to work for all kinds of
  1538. 1:03:00different protocols.
  1539. 1:03:03Sometimes like this clock could be used
  1540. 1:03:06for a spy clock and that only needs to
  1541. 1:03:08be an output, right? So they might have
  1542. 1:03:11some pins that are only designed to be
  1543. 1:03:13clock outputs. So that's why you can set
  1544. 1:03:15it up like this.
  1545. 1:03:19Make sense so far?
  1546. 1:03:23All right. To summarize,
  1547. 1:03:26pros and cons. I squared C. It's really
  1548. 1:03:29easy to wire up. Just two wires plus
  1549. 1:03:31ground. Uh it's widely supported in
  1550. 1:03:34industry. Um the cons the open
  1551. 1:03:38collector. So that that end MOSS it
  1552. 1:03:41could make debugging a little bit
  1553. 1:03:43harder. We don't know which device is
  1554. 1:03:44pulling the line low. It could be either
  1555. 1:03:46of them. So it might be a little bit
  1556. 1:03:47harder to debug what's going on there.
  1557. 1:03:50We have that speed power tradeoff. So
  1558. 1:03:53when we decrease those resistor values,
  1559. 1:03:56that means there's going to be more
  1560. 1:03:57current going through those resistors
  1561. 1:03:59and therefore they're going to be
  1562. 1:04:00dissipating more heat, more power. So
  1563. 1:04:03the faster we go, the more power we use.
  1564. 1:04:07Um, and that that max speed is
  1565. 1:04:09determined by kind of the hardware, the
  1566. 1:04:11resistors, the parasitic capacitance.
  1567. 1:04:14That's going to define how fast we can
  1568. 1:04:15actually go. And there's no hardware
  1569. 1:04:18arbitration. It's kind of a pro and a
  1570. 1:04:20con. We don't need more wires.
  1571. 1:04:22Um but what we have to do is for every
  1572. 1:04:26transaction we have to send an address
  1573. 1:04:29before we send data. Okay. And that adds
  1574. 1:04:31some overhead to each transaction. So I
  1575. 1:04:33really need to send two bytes every time
  1576. 1:04:36I want to send one. Okay. So that could
  1577. 1:04:38be a potential downside where with UART
  1578. 1:04:41and spy I can just send the data
  1579. 1:04:43whenever I want. I don't have to have
  1580. 1:04:45that address phase as part of the
  1581. 1:04:47transaction.
  1582. 1:04:51All right, that's I squared C. Yeah.
  1583. 1:04:55>> In practice, how many devices do you
  1584. 1:04:56have connected to an I2C bus? Like I
  1585. 1:04:59know there's seven bits for addressing,
  1586. 1:05:01so there could be a max of three to
  1587. 1:05:03seven different devices, but in
  1588. 1:05:04practice, like what do you see?
  1589. 1:05:06>> Uh well, the cool thing is is we can
  1590. 1:05:09just go slower and slower as we add more
  1591. 1:05:11and more devices. Uh, so that
  1592. 1:05:15capacitance like if I have 100 devices
  1593. 1:05:17that means I got a lot of wire going on,
  1594. 1:05:19right? I got a lot of space. Maybe this
  1595. 1:05:21thing is spread out in a house or
  1596. 1:05:24something like that. I wouldn't use I
  1597. 1:05:25squared C for a house, but I suppose you
  1598. 1:05:28could do it. Uh, but you're going to
  1599. 1:05:30have a lot of capacitance. And so what
  1600. 1:05:32that means is you have to go really
  1601. 1:05:34slow. Like maybe you go one kilobit per
  1602. 1:05:37second. Okay, so that's kind of you have
  1603. 1:05:39to play around with it. I can't give you
  1604. 1:05:41a definitive answer because it really
  1605. 1:05:42depends on all all kinds of different
  1606. 1:05:44variables.
  1607. 1:05:46Okay. But yeah, the the limit is the
  1608. 1:05:48address 128 for seven uh seven bits, but
  1609. 1:05:53I can increase that to 10 bits if I want
  1610. 1:05:56to add even more devices or whatever. I
  1611. 1:05:59forget what the the max value is for
  1612. 1:06:00address. You could increase that as
  1613. 1:06:02well.
  1614. 1:06:04Any other questions?
  1615. 1:06:09Okay.
  1616. 1:06:10So, we're going to do a quick review and
  1617. 1:06:12then we're going to do a worksheet.
  1618. 1:06:16All right. So, UART, we got the TX and
  1619. 1:06:20the RX pin. We connect the TX to the RX
  1620. 1:06:24and same going the other way around. Um,
  1621. 1:06:27this is commonly used for devices that
  1622. 1:06:29just need to like continuously stream
  1623. 1:06:31data. Okay, we've already kind of used
  1624. 1:06:33UART in lab, right? We use UART to
  1625. 1:06:36transmit data from the XMC to the
  1626. 1:06:38computer on the terminal.
  1627. 1:06:42Often when you're playing around with
  1628. 1:06:44GPS receivers, they're almost always
  1629. 1:06:47going to use UART. That's kind of a
  1630. 1:06:49common use case where uh GPS is used and
  1631. 1:06:52that's just because the GPS is just
  1632. 1:06:54continuously sending information about
  1633. 1:06:56where it is. Okay, so that might be a
  1634. 1:06:58good use case for UR.
  1635. 1:07:01The the the thing about yard is we don't
  1636. 1:07:04have a clock pin. So the two devices
  1637. 1:07:06have to pre-negotiate
  1638. 1:07:09what uh baud rate they're going to run
  1639. 1:07:11at. So you have to kind of hardcode that
  1640. 1:07:13beforehand. And that's the only way that
  1641. 1:07:16they can talk to each other is if they
  1642. 1:07:17know at what speed uh the data is being
  1643. 1:07:20sent because there's no clock wire.
  1644. 1:07:22Okay. Any questions on UR
  1645. 1:07:30asynchronous clock? We need to do that
  1646. 1:07:32that clock recovery where we're over
  1647. 1:07:34sampling the data so that we can see
  1648. 1:07:37where those edges are and can figure out
  1649. 1:07:39what the clock actually is.
  1650. 1:07:44Okay, spy. We got those four wires. The
  1651. 1:07:48two data wires allows us to do full
  1652. 1:07:50duplex. We got the clock that's sent by
  1653. 1:07:53the controller. Um, anytime there's a
  1654. 1:07:56transaction, the controller
  1655. 1:07:57[clears throat] has to initiate that. As
  1656. 1:08:00we add more and more devices, we have to
  1657. 1:08:01add more and more chip selects. It's
  1658. 1:08:03very similar to uh APB. If you remember
  1659. 1:08:07APB, we had something called P select.
  1660. 1:08:10Same idea here, right? You need an
  1661. 1:08:12additional wire in order to add more
  1662. 1:08:14peripherals.
  1663. 1:08:16Um,
  1664. 1:08:18a good way to think about them is is
  1665. 1:08:19shift registers sha uh shifting data in
  1666. 1:08:22and out.
  1667. 1:08:24And some of the stuff is not
  1668. 1:08:26standardized. So like that clocking
  1669. 1:08:28stuff where we're actually clocking the
  1670. 1:08:29data on the rising edge, falling edge,
  1671. 1:08:31the polarity and the the phase that's
  1672. 1:08:35things that our microcontroller has to
  1673. 1:08:37support all of those in order to talk to
  1674. 1:08:38all the different devices out there.
  1675. 1:08:42And the packet size is t all of these,
  1676. 1:08:44you know, packet size is typically 8
  1677. 1:08:46bits, but you can play around with that
  1678. 1:08:48with spy.
  1679. 1:08:51Then I squared C. We got those two
  1680. 1:08:53wires. We're doing open collector.
  1681. 1:08:55That's where these devices are pulling
  1682. 1:08:57the lines low. We need those external
  1683. 1:08:59resistors which are basically doing the
  1684. 1:09:02one part of this.
  1685. 1:09:04Uh we have these possible addresses. So
  1686. 1:09:07each peripheral is going to have its uh
  1687. 1:09:09own address.
  1688. 1:09:10Hopefully they're not the same,
  1689. 1:09:12otherwise it'll be an issue. If you want
  1690. 1:09:14to broadcast, use address zero. And
  1691. 1:09:17those are the speeds for different
  1692. 1:09:19resistor values.
  1693. 1:09:21Okay, so here's kind of a summary
  1694. 1:09:24of all of those together. And what I'm
  1695. 1:09:27going to challenge you to do is make an
  1696. 1:09:30even better protocol. I want a protocol
  1697. 1:09:32that only uses one wire. Right? We had
  1698. 1:09:35we had I squared C. It used two. That's
  1699. 1:09:38too much. I only want one. Okay. So, I
  1700. 1:09:41want you guys to think about with your
  1701. 1:09:42your neighbor. I have a sheet here. I
  1702. 1:09:45want you to think about Do we have time?
  1703. 1:09:47We got 20 minutes. Um, we have 10
  1704. 1:09:50minutes. Okay. So, we kind of have to
  1705. 1:09:52hurry up. I'm going to [snorts] give you
  1706. 1:09:545 minutes to think about
  1707. 1:10:25Hello.
  1708. 1:11:04I feel
  1709. 1:11:26I think
  1710. 1:11:45I don't
  1711. 1:11:51Hallelujah.
  1712. 1:12:24transmit.
  1713. 1:12:55out.
  1714. 1:13:12Sorry.
  1715. 1:13:15[sighs]
  1716. 1:13:29Sorry.
  1717. 1:13:56You
  1718. 1:14:07wonderful.
  1719. 1:14:24Amen.
  1720. 1:14:43We might
  1721. 1:14:46Yeah.
  1722. 1:14:56I need something.
  1723. 1:15:33Oh yeah.
  1724. 1:16:02All right, we got a couple more minutes.
  1725. 1:16:04So, let's let's talk about how this
  1726. 1:16:05might be possible. Who thinks they know
  1727. 1:16:08how this can be done?
  1728. 1:16:10>> Yeah. Um I know like [snorts]
  1729. 1:16:15basically
  1730. 1:16:18only one line
  1731. 1:16:20talk at a time.
  1732. 1:16:21>> Yeah. Okay. And how would the So is that
  1733. 1:16:26just one device talking to one device?
  1734. 1:16:28>> Yeah.
  1735. 1:16:29>> Okay. [snorts] What if I wanted to talk
  1736. 1:16:30to multiple devices?
  1737. 1:16:34>> How would I do that?
  1738. 1:16:36>> Any ideas? [clears throat]
  1739. 1:16:41one way. [clears throat]
  1740. 1:16:44>> What do you think?
  1741. 1:16:45>> Um, you can make it like a walkie-talkie
  1742. 1:16:48where you have some that that indicates
  1743. 1:16:50which device should be talking and all
  1744. 1:16:51the other ones can like only one device
  1745. 1:16:54can communicate at one time.
  1746. 1:16:56>> Okay. So, it just whenever one device
  1747. 1:16:58wants to talk, it's just like, hey, I
  1748. 1:17:00want to talk.
  1749. 1:17:00>> Yeah.
  1750. 1:17:01>> But what about I square C? How does it
  1751. 1:17:03do it? Yeah.
  1752. 1:17:04>> Like you can use addresses.
  1753. 1:17:06>> You can use addresses. Yeah. controller.
  1754. 1:17:10>> Yeah. Well, maybe maybe we could do it
  1755. 1:17:12that way. Remember how we did
  1756. 1:17:13arbitration of vice vers with multiple
  1757. 1:17:15controllers? Maybe we can do the same
  1758. 1:17:16thing.
  1759. 1:17:17>> Okay. So, what can we actually do? We
  1760. 1:17:20can do we can do it all with one wire.
  1761. 1:17:23Um we basically are taking a hybrid
  1762. 1:17:25between uh UART where we predefined the
  1763. 1:17:29clock. Okay. So all the devices are
  1764. 1:17:32talking at the same speed, but then
  1765. 1:17:34we're also kind of using I squ C where
  1766. 1:17:36we're using a single wire to talk back
  1767. 1:17:38and forth. We're also using the
  1768. 1:17:40functionality of I squared C where we
  1769. 1:17:43have addresses and we're using addresses
  1770. 1:17:45to let uh which device we're talking to
  1771. 1:17:49know that we're talking to it. And we're
  1772. 1:17:51going to take it one step further and
  1773. 1:17:53what if I said, okay, we can do data,
  1774. 1:17:55all the data we want on one line. We're
  1775. 1:17:58also going to power this device with
  1776. 1:18:00that one wire. So, we're going to power
  1777. 1:18:02this device and send all of our data. We
  1778. 1:18:05can actually do that. And so, let me
  1779. 1:18:08just pull up false real quick. I know we
  1780. 1:18:10just got 2 minutes.
  1781. 1:18:14Um, so how would we actually do that?
  1782. 1:18:18So, here is I squared Z. Here is that
  1783. 1:18:22one wire interface that we made. So, we
  1784. 1:18:24have that pull-up resistor. Okay, that
  1785. 1:18:27is uh making sure that we can talk on
  1786. 1:18:30the same wire. Okay, that's what that's
  1787. 1:18:32doing there. And we can have both
  1788. 1:18:35devices
  1789. 1:18:37talk
  1790. 1:18:38back and forth. We could do some
  1791. 1:18:41addressing if we wanted. Okay, then what
  1792. 1:18:45about actually powering the device? So,
  1793. 1:18:47let's say I had uh for some reason I had
  1794. 1:18:50like a remote sensor that was not
  1795. 1:18:52connected to my PCB and I didn't want to
  1796. 1:18:54run three wires to it. I just wanted to
  1797. 1:18:56run two wires. So, I wanted to provide
  1798. 1:18:58power, data, and ground with just two
  1799. 1:19:01wires. I can do that. Since I got this
  1800. 1:19:04pull-up resistor here, we got 5 volts on
  1801. 1:19:08this data line. Well, we could harvest
  1802. 1:19:10that that voltage and we could store the
  1803. 1:19:13little capacitor here, big capacitor.
  1804. 1:19:16And so while this is harvesting data,
  1805. 1:19:19even though the line is going low, it's
  1806. 1:19:21going low for a short amount of time,
  1807. 1:19:24that capacitor still has that voltage
  1808. 1:19:27there. Um, and it keeps the device on.
  1809. 1:19:30Okay, so kind of a clever way to do data
  1810. 1:19:33power all just one wire. It's possible.
  1811. 1:19:36It's going to be kind of slow, but we
  1812. 1:19:39can do it. Okay. And we took all the
  1813. 1:19:40techniques that we learned from all
  1814. 1:19:42those different serial uh peripherals or
  1815. 1:19:44serial uh communication protocols and
  1816. 1:19:48combine them all into one.
  1817. 1:19:50All right, one minute. Any last
  1818. 1:19:52questions?
  1819. 1:19:56All right, see you on Wednesday. Thanks.

About this transcript

This page contains the full transcript of EECS 373 - Fall 2026 - Lecture 12: "Serial Buses: I2C and SPI" by Interactive Sensing and Computing Lab , generated from the public captions YouTube serves with the video. The transcript has 12,546 words across 1,819 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.

What you can do with it

Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to translate the transcript into 100+ languages.

Free YouTube transcript tool

YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.