dikris
Active Member
Offline
Posts: 205
Thank You
-Given: 301
-Receive: 69
|
|
« on: May 18, 2006, 09:49:04 09:49 » |
|
Hi all, I have CCS project with PIC18f452 and 8 mcp23s08.I want to make 4 of them inputs with pull-up and another 4 - Outputs.I use hardware addressing pin(A0,A1) . Inputs and otputs have separately CS. Can you advice me how to init those chips.When I send command to outputs all 4 chips recive same information.Any driver idea. I wrote this driver: void init_SPI() { output_low(SPI_CLK); delay_us(50); output_low(SPI_DI); output_high(OUTPUTS_CS); output_high(INPUTS_CS); delay_us(50); } void mcp32s08_SendByte(BYTE data) { BYTE i; delay_us(2); for(i=0; i<8; ++i) //SEND DATA { if(bit_test(data, 7)) output_high(SPI_DI); else output_low(SPI_DI); // data=data>>1; delay_us(60); output_high(SPI_CLK); delay_us(40); output_low(SPI_CLK); data <<= 1; } }
void mcp32s08_write(BYTE address,BYTE reg,BYTE value,BYTE io) { output_low(SPI_CLK); output_low(SPI_DI); if(io==0) //outputs output_low(OUTPUTS_CS); else //inputs output_low(INPUTS_CS);
mcp32s08_SendByte(address); //SEND OP CODE (ADDRESS) mcp32s08_SendByte(reg); //SEND REGISTER mcp32s08_SendByte(value); //SEND VALUE init_SPI(); }
void mcp32s08_SetPulUp(BYTE address) { address=address<<1; address=0x40+address; mcp32s08_write(address,MCP23s08_GPPU,0xFF,1); } void mcp32s08_SetIOCON(BYTE address,BYTE dir) { address=address<<1; address=0x40+address; mcp32s08_write(address,MCP23s08_IOCON,0x04,dir); } void mcp32s08_Out(BYTE address,BYTE value) { address=address<<1; address=0x40+address; mcp32s08_write(address,MCP23s08_GPIO,value,0); }
void mcp32s08_init(BYTE address,BYTE dir) { BYTE value; address=address<<1; address=0x40+address; if(dir==1) value=0xFF; else value=0x00; mcp32s08_write(address,MCP23s08_IODIR,value,dir); } And the code of init is: for(i=0; i<4; ++i) //INPUTS { mcp32s08_SetIOCON(i,1); mcp32s08_SetPulUp(i); //Pull Up - Internal mcp32s08_init(i,1); } for(i=0; i<4; ++i) //OUTS { mcp32s08_SetIOCON(i,0); mcp32s08_init(i,0); mcp32s08_Out(i,0x00); //All Outs '0' } mcp32s08_Out(0,0x01); //Here is the problem
After this bit 0 of all outs is 1, not 1 on first chip only. Sorry of my English.
|