Forum Rule: Always post complete source code & details to reproduce any issue!
Page 2 of 2 FirstFirst 1 2
Results 26 to 31 of 31

Thread: Teensy 3.2 and MCP23S17 expanded i/o

  1. #26
    Senior Member mortonkopf's Avatar
    Join Date
    Apr 2013
    Location
    London, uk
    Posts
    898
    good to know that you know which mcp chip is which re addresses. hopefully you can see which teensy pins are being used for the spi bus, this is going to be crucial in getting the mcp working. on the mcp chip its the bottom left four pins that you need to trace back to the teensy pins and see which ones go where. if you can confirm where the traces go, you can set the spi correctly

  2. #27
    Junior Member
    Join Date
    Jun 2019
    Posts
    15
    Hello Mortonkoft. I took it upon your advice to ring out the first MCP23S17. I've enclosed a picture of what I found. The blocked text are pins from the Teensy. Note that on the MCP23S17, pin 19 - INTB, there is no connection. I checked to see if pin 19 was connected to any other MCP23S17's pin 19 and there seems to be no connection. At the moment, it seems that I need to change the Teensy pin 14 (in the code) to pin 13. So I did, but no change from the previous operation. I see that pin 9 of the MCP23S17 is suppose to be connected to +++ , and it is, but not from the Teensy's pins but from the external +3.3 power source; which is not hooked up. In the initial code, the GCU ran fine without any external power - and the LED's worked at the time. As far as the other MCP23S17's pins, I do not know if the software agrees with the current layout.

    Click image for larger version. 

Name:	1st MCP23S1 connections.jpg 
Views:	8 
Size:	95.3 KB 
ID:	16957

  3. #28
    Junior Member
    Join Date
    Jun 2019
    Posts
    15
    Hello. Some questions about the above examples.
    1) "mcp23s17 mcp0(10, 0x20,30000000);//all three ground" What is the 30000000 ?
    2) "mcp0.gpioRegisterWriteByte(mcp0.IODIR,0b00011 111, true);" Since it seems that INTB doesn't seem to be connected, and there is no IODIRA or ODIRB instructions in the examples, just IODIR, shouldn't it be ...0b1111111111111111, true) for 16 bits of input? By the way, I did try to use IODIRA and I got a compilation error: 'class mcp23s17' has no member named 'IODIRA'.
    3) Speaking about above, " mcp0.gpioPinMode(INPUT);" and "mcp0.gpioRegisterWriteByte(mcp0.IODIR,0b00011 111, true);" are both required?
    4) Does taking into account the status (rising or falling of a signal) need to be done?
    5) Using mcp0 for the first MCP23S17 does not seem to be separate from mcp1, etc. as when I do get a change of state, all show 1111111111111111 even though I specifically make mcp6 and mcp7 outputs. Is there a different method to distinguish between the MCP23S17's? Thanks.

  4. #29
    Senior Member mortonkopf's Avatar
    Join Date
    Apr 2013
    Location
    London, uk
    Posts
    898
    hi, datasheet: http://ww1.microchip.com/downloads/e.../20001952c.pdf

    The 16-bit I/O port functionally consists of two 8-bit ports (PORTA and PORTB). The MCP23X17 can be configured to operate in the 8-bit or 16-bit modes via IOCON.BANK.
    if you have a read of the GitHub repository for the library https://github.com/sumotoy/gpio_expander
    , read the part: "[TIP] What about SPI transactions?"

    The library it's fully compatible with SPI transactions! But it's not automatic since many users use this library inside other libraries so you can still use in legacy mode even if you have a SPI Transaction compatible IDE. You need to add a parameter to the instance to force SPI Transaction! es. mcp23s17 mcp(gpio_cs_pin,gpio_adrs,30000000); I've added a 30Mhz parameter to the end, Teensy will automatically select the higher frequency but you can use any frequency (supported) you want in relation tho the chip you are using, the lenght of SPI lines, etc. If you use SPI transactions remember that the other SPI devices have to use SPI Transaction compatible libraries too!
    RE: not having indecent reading:
    5) Using mcp0 for the first MCP23S17 does not seem to be separate from mcp1, etc. as when I do get a change of state, all show 1111111111111111 even though I specifically make mcp6 and mcp7 outputs. Is there a different method to distinguish between the MCP23S17's? Thanks.
    its hard to tell without seeing your code whether its to do with the settings or the way you loop through the reads, have you properly set your variable for storing, etc. it could be anything. But no, have a read of port settings regarding why the 16bit read to a stored variable does not work that way. you will also need to make sure that you have set the chip to use address bits.The slave address contains four fixed bits and three user-defined hardware address bits (if enabled via IOCON.HAEN) (pins A2, A1 and A0) with the read/write bit filling out the control byte. this is done here

    IOCON = BANK MIRROR SEQOP DISSLW HAEN ODR INTPOL -NC- */
    mcp.gpioRegisterWriteByte(mcp.IOCON, 0b01101000);//HAEN,SEQOP,MIRROR
    Last edited by mortonkopf; 07-12-2019 at 09:26 AM.

  5. #30
    Senior Member mortonkopf's Avatar
    Join Date
    Apr 2013
    Location
    London, uk
    Posts
    898
    for setting the function of the chip, see page 21 of the data sheet : IOCON: I/O EXPANDER CONFIGURATION REGISTER
    this sets out why you have the bit settings as described above.
    IOCON = BANK MIRROR SEQOP DISSLW HAEN ODR INTPOL -NC- */
    mcp.gpioRegisterWriteByte(mcp.IOCON, 0b01101000);//HAEN,SEQOP,MIRROR

  6. #31
    Junior Member
    Join Date
    Jun 2019
    Posts
    15
    Hello Mortonkopf. I'm a bit confused. In statement #19, I showed my code. I will look over the GitHub repository. I did make a note of the IOCON:
    // 0b bit7=BANK:1=separate,0=same
    // bit6=MIRROR:1=INT pin connected,0=INTA-PORTA;INTB-PORTB
    // bit5=SEQOP:1=SEQOP disable;no increment,0=SEQOP enabled;address pointer increments
    // bit4=DISSLW:1=slew rate disabled, 0=slew rate enabled
    // bit3=HAEN:1=enables address pins, 0=disables address pins
    // bit2=ODRverrides INTPOL if set. 1=open-drain output, 0=active driver output
    // bit1=INTPOL:sets polarity of INT output pin. 1=active high, 0=active low
    // bit0=N/A:0

    Since pin 19 INTB, does not seem to have any connections, am I correct that bit 7 should be (0) and thus bit 6 should be (1)? I don't understand bit 5 or 4. Since the MCP23S17 has the "S," I assume bit 3 is (1) by default. And I don't understand bit 2 and 1. Also, shouldn't the IODIR show 16 bits instead of 8 if PORTA and PORTB are combined? Just for grins, I removed the 1st PCB that contains only the Teensy and the 8 MCP23S17's and grounded the I/O pins to see if I could see a difference but nothing happened. Again, I greatly appreciate your time and information.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •