A newb interfacing the SPI interface... - Page 1
Forum section: electronics / beginners

author: fenclu
author_rank: Regular Contributor
timestamp: January 29, 2013, 08:54:06 pm
content: I've been designing this PSU which is quite similar to the bench version of the uSupply. Now I'm starting to interface the SPI interface (LOL). I've got a couple of questions:1) What's the role of the interrupt pin on the MCP23S08 (Dave when using the I2C version of this expander mentioned that it's useful to use the INT pin for the inputs)?2) How do I implement this interrupt in my code?3) Is it possible to put a CS pin for a DAC on one of those I/O pins?4) Is there a simple way of translating a value (0-1023) into a binary byte?

author: madires
author_rank: Super Contributor
timestamp: January 29, 2013, 09:40:56 pm
content: Quote from: fenclu on January 29, 2013, 08:54:06 pmThat pin tells the MCU that something on an I/O pin (configured as input) has changed, like a pressed push-button. The MCU then polls the MCP23S08 for that change. That's called interrupt driven I/O. The MCU doesn't need to poll the MCP23S08 every X msec wasting time.QuoteSee the documentation of your MCU and check the Internet for examples. If you are completely new to the concept of interrupts you'll need some time to understand it. Basically you have to write a (short) interrupt handler and setup the used I/O pin of the MCU to create an interrupt. The difficult part is to integrate that into the main processing loop.QuoteYes, but it's mostly easier to connect the DAC directly to the MCU. If the MCU doesn't got enough I/O pins select a model with more pins.QuoteA byte got 8 bits. 2^8 = 256. Won't work anyway :-)

author: Mr Smiley
author_rank: Frequent Contributor
timestamp: January 29, 2013, 10:22:00 pm
content: Quote from: fenclu on January 29, 2013, 08:54:06 pmDo you mean, how do you convert 1024 (decimal ) ( 10 bit binary number ) into a format that you can see on a lcd or serial monitor ?

author: fenclu
author_rank: Regular Contributor
timestamp: January 29, 2013, 10:29:10 pm
content: No, no. I've got to send a register to the DAC and the 12 last bits are the bits that set the value on the output (it's a 10 bit DAC, so there are 2 "don't care bits"). And I had a concept of setting the value with a rotary encoder (so it's easier to write a code that's just adding one "bit" with each step) and storing the value in the internal EEPROM and then translating the VALUE (0-1023) into a binary byte. I don't know, it just seems easier that way. And if it's not possible, then it's going to be a giant pain in the arse trying to increase the value by changing the register itself.

author: madires
author_rank: Super Contributor
timestamp: January 29, 2013, 10:49:21 pm
content: Quote from: fenclu on January 29, 2013, 10:29:10 pmIf I got you right, you simply need something like a 10 bit variable? Use a 16 bit variable and write a small wrapper function which takes care about overflows and allows you to de/increase the value. It's easy to extract the lower 8 and upper 8 (2 + 6 zeros) bits, if you have to send the value bytewise.

author: Mr Smiley
author_rank: Frequent Contributor
timestamp: January 29, 2013, 10:56:30 pm
content: Are you using C, Asm or an Atmeg environment to write you code ?

author: fenclu
author_rank: Regular Contributor
timestamp: January 30, 2013, 09:14:47 am
content: Duh, i forgot to mention the basic thing...i'm using the Arduino Uno

author: madires
author_rank: Super Contributor
timestamp: January 30, 2013, 11:25:11 am
content: Quote from: fenclu on January 30, 2013, 09:14:47 amIt's your lucky day :-) I've written a Arduino lib for the MCP23S08 and some sample code for testing. If you like I could sent you a copy.

author: fenclu
author_rank: Regular Contributor
timestamp: January 30, 2013, 11:33:50 am
content: Yes, pleasehere's my email: jakubf2007@gmail.com