Author Topic: SBC44UC and MCP23008  (Read 8385 times)

HPvanRiemsdijk

  • Newbie
  • *
  • Posts: 4
    • View Profile
SBC44UC and MCP23008
« on: September 24, 2007, 12:14:17 AM »
Ive bought the SBC44UC board and added the MCP23008 I/O expander and 24LC512 serial EEPROM. Currently Im working on firmware to facilitate all the IO functions of the SBC44UC board, unfortunately I cant get the IO ports of the MCP23008 I/O working. With the following code all MCP23008 ports should be configured as output and should give 1. (To reduce the length of the post, Ive replaced in relevant code with ..). Unfortunalty the following code is not working. Can anyone offer some help?  :-)

io_cfg:
Code: [Select]

/** TRIS registers ************************************************/
#define mInitRegA()         LATA &= 0b00000000; TRISA &= 0b11111111;
#define mInitRegB()         LATB &= 0b00000000; TRISB &= 0b10101111;
#define mInitRegC()         LATC &= 0b00000000; TRISC &= 0b11111011;
#define mInitRegD()         LATD &= 0b00000000; TRISD &= 0b00000000;
#define mInitRegE()         LATE &= 0b00000000; TRISE &= 0b00000111;
.

User.c:
Code: [Select]
...........
/** I N C L U D E S **********************************************************/
#include <p18cxxx.h>
#include <usart.h>
#include "system\typedefs.h"
#include "system\usb\usb.h"
#include "user\user.h"
#include <i2c.h> //I2C

..

void UserInit(void)
{   
/** Init IO registers***********************************************/
    mInitRegA();
mInitRegB();
mInitRegC();   
mInitRegD();   
mInitRegE();   

/** Set I2c ********************************************************/
INTCON2bits.RBPU = 0;          // enable Pullups for PortB-Pins
OpenI2C(SSPENB | MASTER, SLEW_OFF); // Initialize the I2C as a master
SSPADD=49;                      // (20MHz/100KHz)/4 - 1 = 49;

/** Configure  MCP23008 ******************************************/
StartI2C();            // Send a start
IdleI2C();      // Wait for i2c to be ready
WriteI2C(0x40);    // slave address for write Adres (write) = 01000000 (0x40)
IdleI2C();                // Wait for i2c to be ready
WriteI2C(0x00);    // Select conf. en control. register
IdleI2C();          // Wait for i2c to be ready
WriteI2C(0x00);    // Set all to output.
IdleI2C();            // Wait for i2c to be ready
StopI2C();

StartI2C();
IdleI2C();          // Wait for i2c to be ready
WriteI2C(0x40);    // slave address for write Adres (write) = 01000000 (0x40)
IdleI2C();              // Wait for i2c to be ready
WriteI2C(0x0A);    // Select the OLAT post to set output
IdleI2C();                // Wait for i2c to be ready

/** Turn on leds ******************************************/
WriteI2C(0xff);    // Set output 00000000 = 0x00/ 11111111 = 0xFF
IdleI2C();                // Wait for i2c to be ready
StopI2C();
}//end UserInit
..

modtro2

  • Administrator
  • Hero Member
  • *****
  • Posts: 564
    • View Profile
Re: SBC44UC and MCP23008
« Reply #1 on: September 24, 2007, 04:25:54 AM »
Do you also initialize your registers somewhere else? Your mInitRegX macros only clear bits, and do not set them. You are ANDing the existing register value with the given literal - will only clear bits. Or, are you assuming that the registers are all 1's? This is probably right for the TRIS registers anyway, so I guess this should not be the problem.

HPvanRiemsdijk

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: SBC44UC and MCP23008
« Reply #2 on: September 24, 2007, 04:48:00 AM »
Actually I dont initialize my registers somewhere else, so you are probably right I shouldt be  ANDing the registers here. I will change the &= to =, but I dont expect this will solve the problem. Do you have any other suggestions?

OmarZ

  • Hero Member
  • *****
  • Posts: 243
    • View Profile
Re: SBC44UC and MCP23008
« Reply #3 on: September 24, 2007, 10:20:49 AM »
I'm using MCP23008 with SBC65EC. In attachment the code.

HPvanRiemsdijk

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: SBC44UC and MCP23008
« Reply #4 on: September 24, 2007, 11:50:47 AM »
Thanks for posting your code!! I will try this out and report my findings. Thanks again.  :-)

HPvanRiemsdijk

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: SBC44UC and MCP23008
« Reply #5 on: May 04, 2009, 10:16:34 AM »
Last week I decided to pickup this project again, and this time with more luck. I've modified the UWB project (http://www.schmalzhaus.com/UBW/) firmware D to work on the sbc44uc board and MCP23008 I/O expander (Without interupt pin).
The firmware offers the following features using a virtual com port:
- Status led
- Set and read a total of 32 digital I/O pins
- Set and read max 10 analog input pins
- Set 2 PWM signals on pin C1 and/ or C2
- Control up to 15 servos
- I/O pins for MCP23008 can be addressed as virtual port F (No I2C commands needed)
- Some other UBW features I dont need and didn't test.

To make live a little easier I've made a windows application (vb.net) to control most of these features:
- Connect to sbc44ucr
- Set and read a total of 32 digital I/O pins
- Set and read max 10 analog input pins
- Set 2 PWM signals on pin D1 and/ or D2
- Set analog sample rate
- Set digital sample rate

Please use the UBW firmware D documentation to learn more about valid commands to control the sbc44ucr using this firmware. Remember the UBW uses Port A, B, C, D and E. This firmware adds Port F as virtual port to control the MCP23008 I/O expander.

To use this firmware a custom microchip driver is needed, please check to the UBW documentation.

Although this firmware and frontend works pretty good for me there are some (serious) know errors and missing features. If there is anyone out there who knows what he or she is doing (In opposite to me) and find some time to fix these errors/ wishes, please feel free to do so (and it will be greatly appreciated). For everyone else, I hope this firmware & software saves you some time, blood, sweat and tears.

Known errors
- Delay on reading input (An input of 5 ms sometimes returns 1 for several seconds)
- Pin D5 is shows unexpected behavior (always on)
- Unexpected behavior when 8 or more analog inputs are selected (All analog inputs show incorrect values)
- Pin B1 is shows unexpected behavior (Other activities on this pin?)

Wishes:
- Read/ write words to internal and external EEPROM (transparent)
- Build UBW servo control in vb.net GUI
- Possibility to switch on/ off external IO and EEPROM (Using c command)
- Cleanup unused code