|
|
View previous topic :: View next topic |
Author |
Message |
krakatau
Joined: 19 Feb 2009 Posts: 9
|
beginning the spi, please help |
Posted: Thu Feb 19, 2009 9:59 am |
|
|
I'm new in ccs, but i need to spi communication. I tried this code.
for master
Code: |
void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_spi(SPI_MASTER | SPI_L_TO_H);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
// TODO: USER CODE!!
while(1)
{
output_low(pin_a5);
spi_write(0XAA);
delay_ms(1);
output_high(pin_a5);
}
} |
for slave
Code: |
int x;
void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_spi(SPI_SLAVE);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
// TODO: USER CODE!!
delay_ms(100);
while(1)
{
x=spi_read();
delay_ms(1);
output_b(x);
}
}
|
the above code is operating
but i want send two byte sequential (master to slave).
so i want see on leds.1 second 0xAA one second 0x55.
Code: |
void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_spi(SPI_MASTER | SPI_L_TO_H);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
// TODO: USER CODE!!
while(1)
{
output_low(pin_a5);
spi_write(0XAA);
delay_ms(1);
output_high(pin_a5);
delay_ms(1000);
output_low(pin_a5);
spi_write(0x55);
delay_ms(1);
output_high(pin_a5);
}
} |
the above code
i can see 0xAA but i can't 0x55 in outputs
what can i do?
thanks |
|
|
ECACE
Joined: 24 Jul 2006 Posts: 94
|
|
Posted: Thu Feb 19, 2009 12:54 pm |
|
|
From your code:
Code: | while(1)
{
output_low(pin_a5);
spi_write(0XAA);
delay_ms(1);
output_high(pin_a5);
delay_ms(1000);
output_low(pin_a5);
spi_write(0x55);
delay_ms(1);
output_high(pin_a5);
}
} |
You pass AA out to the slave, wait 1 sec, pass 55 out to the slave, then imediately send AA again.
Your slave is probably displaying it, but it is happening so fast that you can't see it.
You need to add a delay_ms(1000) after your 0x55 transmition. You will probably see it then.
So you should have:
Code: | while(1)
{
output_low(pin_a5);
spi_write(0XAA);
delay_ms(1);
output_high(pin_a5);
delay_ms(1000);
output_low(pin_a5);
spi_write(0x55);
delay_ms(1);
output_high(pin_a5);
delay_ms(1000); // Add this delay line to your code
} |
} _________________ A HW Engineer 'trying' to do SW !!! Run!!! |
|
|
krakatau
Joined: 19 Feb 2009 Posts: 9
|
|
Posted: Fri Feb 20, 2009 1:25 am |
|
|
Yes, I've done.
I don't believe that and I didn't see delay_ms. Exactly as you say. I tried very much on yesterday but I couldn't. But this morning I saw your message. I tried. It was done.
Thank you very much ECACE.
The following code is executing.
for master:
Code: |
void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_spi(SPI_MASTER | SPI_L_TO_H);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
// TODO: USER CODE!!
while(1)
{
output_low(pin_a5);
spi_write(0XAA);
delay_ms(1);
output_high(pin_a5);
delay_ms(1000);
output_low(pin_a5);
spi_write(0x55);
delay_ms(1);
output_high(pin_a5);
delay_ms(1000);
}
}
|
For slave:
Code: |
int x;
void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_spi(SPI_SLAVE);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
// TODO: USER CODE!!
delay_ms(100);
while(1)
{
x=spi_read();
delay_ms(1);
output_b(x);
}
} |
|
|
|
|
|
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
|