SPI Device MCP23S09 Clarification of device operation
I to am trying to use the MCP23S09 SPI GPIO Device, have searched Microchip and the Forum and there seems to be little if any info on this device, apart from the Datasheet. No application notes or examples etc. The Datasheet is not the best as it is shared with the spec for the MCP23009 I2C device. What is not clear in the Datasheet is as follows. Although the MCP23S09 being an SPI device, does use the hardware chip select method and no hardware pins for addressing, I find the description of the Control Byte confusing, ok I understand the byte is similar to I2C with Bit 0 as R/W but what I dont understand is why is this required, with Chip select anyway and why is bit 6 set? This implies to me that the control byte for write mode would be %01000000 ie $40 hex, is this so? Next problem is the datasheet does not explain if the Control Byte and a Register Address are sent as one 16bit word or two bytes, followed by a third for the data to set up the register. Does this chip expect serial data sent MSB or LSB first. Also as the datasheet implies that the device defaults to sequential address mode, I presume that one has to write to the IOCON register with Bit 5 set to 1 to disable sequential write. Can Microchip give a definitive example as to the correct handling of the sequence of events I have just described as problematic?
I have written some code in PBP shown below just to get some basic output from the GPIO outputs, to no avail. Have used Oscilloscope amd can see clock and data being sent to the correct pins on the device, via the PBP SHIFTOUT command. Anyway maybe the command in PBP is not doing the job properly? So before I start with machine code/bit banging etc, I do need answers to my problems above which after reading the datasheet from microchip, sheds no light on these issues at all. Please has anyone used this chip I would be most grateful for any help.
' 40 pin Dip PIC 16F887 on Veroboard programmed with Pickit2
' Using SPI with PicBasic Pro
' Fitted with --Microchip MCP23S09 -- SPI GPIO device.
' Pic uses internal CLOCK OSC
' This does not need MPASM and uses PicBasic-Pro Compiler only.
' Alan Randles Feb 2011
@ device pic16f887, LVP_OFF, FCMEN_OFF, IESO_OFF, BOD_OFF, CPD_OFF, MCLR_OFF, PWRT_ON
@ device pic16f887, WDT_OFF, INTRC_OSC_NOCLKOUT
@ device2 WRT_OFF, BOR21V
'------------------------- MC23S09 SPI -----------------------------
Include "modedefs.bas" ' Include shift modes
define SHIFT_PAUSEUS 2000 'slow down shiftclock 2ms for shiftout command
clk Var PORTD.0 ' Clock pin
dout Var PORTD.1 ' Data Out pin
datin Var PORTD.3 ' Data In pin
cs Var PORTD.4 ' Chip Select pin
mode var byte
addr var byte
led var PORTD.2 'led indicates start and end of sequence below
OSCCON = %00110111 'Set Internal clock 500khz easier for view on Oscope
'Have tried at 4,2 and 1mhz also
input datin 'set data in pin to input
high cs 'set chip selct high
low cs 'Take chip selct low on MCP23S09
mode = 0 'Set Shiftout mode have tried 0 and 1
addr = 0 '1st register address in MCP23S09
' Use PicBasic Pro command -shiftout- to send opcode, 1st reg address
' then 11 bytes for the MCP23S09 registers. Assuming MCP23S09 is in
' default mode of Auto address increment?
high cs 'Take chip selct high on MCP23S09