CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

18F452 SPI COMS W/ MPS2308

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
bassplayer



Joined: 24 Jun 2004
Posts: 6

View user's profile Send private message

18F452 SPI COMS W/ MPS2308
PostPosted: Mon Nov 13, 2006 10:37 am     Reply with quote

I've been running the 18F452 in SPI mode w/ the MPS2308 to add extra input switches for months now and it works perfectly. I was just told to add extra outputs now to the design, but I'm having problems configuring the MPS2308 for output mode... there's something simple that I must be doing wrong but can't find it.

Here's the code: (I set up an extra CS signal that is not required in order to debug this software that is not working)
//Here I simply read a DIP switch and output the 8 bit results to both
//a MPS2308 setup for output and port B as an additional image
//The system is running on a 4 MHz crystal
//The dip switch is working the led output chip is NOT

#define TDIP_CLK PIN_C3
#define TDIP_DOUT PIN_C5
#define TDIP_DIN PIN_C4
#define TDIP_CS_SW PIN_A2
#define TDIP_CS_LED PIN_A3

unsigned int val;

void send_byte(int8 val_to_send)
{
int8 count;

for(count=0; count<8; count++)
{
output_bit(TDIP_DOUT, shift_left(&val_to_send,1,0));
delay_us(5);
output_low(TDIP_CLK);
delay_us(5);
output_high(TDIP_CLK);
}

}


int8 get_byte(void)
{
int8 count;
int8 val;

for(count=0;count<8;count++)
{
output_low(TDIP_CLK);
shift_left(&val,1,input(TDIP_DIN));
output_high(TDIP_CLK);
}

return(val);
}



void main()
{

setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);

set_tris_a(0x00);
set_tris_b(0x00);
set_tris_c(0x10);

output_b(0x55);



output_high(TDIP_CS_LED);
output_high(TDIP_CS_SW);
output_high(TDIP_CLK);

output_low(TDIP_CS_SW);
send_byte(0x40);
send_byte(6); //Pull up resistor register
send_byte(0xff); //enable pullups
output_high(TDIP_CS_SW);



output_low(TDIP_CS_LED);
send_byte(0x46);
send_byte(0x05); //configuration register
send_byte(0x3e); //sequential operation disabled
//enable address pins that are both HI
output_high(TDIP_CS_LED);

output_low(TDIP_CS_LED);
send_byte(0x46);
send_byte(0x00); //write to address 0x00
send_byte(0x00); //set for ALL outputs
output_high(TDIP_CS_LED);


output_low(TDIP_CS_LED);
send_byte(0x46);
send_byte(0X0A); //OLAT register
send_byte(0x81);
output_high(TDIP_CS_LED);
delay_ms(200);

while(1)
{
output_low(TDIP_CS_SW);
send_byte(0x41);
send_byte(9); //GPIO register
val = get_byte(); //get dip switches
output_high(TDIP_CS_SW);


output_low(TDIP_CS_LED);
send_byte(0x46);
send_byte(0x0A);
send_byte(val); //send dips to
output_high(TDIP_CS_LED);


output_b(val);

delay_ms(500);
}


}

As a last note, I still have confusion as to the relationship between the OLAT and GPIO registers. I've tried to write the output LED configuration to the GPIO registers as well, but I'm still not having any luck.

Will look forward to hearing the obvious problem that I am having.

Thanks!!!
bassplayer



Joined: 24 Jun 2004
Posts: 6

View user's profile Send private message

Solved my own problem...
PostPosted: Mon Nov 13, 2006 12:11 pm     Reply with quote

I've learned the important lesson of adding extra delays after writing to the MPS23S08 when using it as an output latch. When writing to the latch I only had to add an extra delay and everything works. Back to reading the datasheet.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Nov 13, 2006 12:11 pm     Reply with quote

Quote:
I've been running the 18F452 in SPI mode w/ the [b]MPS2308

Can you verify that part number ? I can't find it. Do you really
mean the MCP23S08 ?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group