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

VS1011 the code SPI is correct?

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







VS1011 the code SPI is correct?
PostPosted: Fri Feb 23, 2007 2:37 am     Reply with quote

Hi,

I have a problem with VS1011 and PIC 18F452, the code is correct for SPI?

Code:
 
   set_tris_a(0x11);
   set_tris_b(0x11);
   set_tris_c(0x90);//
   set_tris_d(0x67); 
   set_tris_e(0x00);

 
 
   output_high(CS_VS1011);  // DISABLE CS VS_1011
   output_low(BYSYNC_VS1011);  // DISABLE BYSYNC VS_1011

 
 
   output_bit(RESET_VS1011,1);                               
   delay_ms(10);
   output_bit(RESET_VS1011,0);                               //reset
   delay_ms(10);
   output_bit(RESET_VS1011,1);                               
 
   Delay_ms(100);                         
   while(!input(DREQ_VS1011) == 1);
 
    output_bit(CS_VS1011,0);                               //Hardware Reset logical level to 0-->1
    delay_ms(10);
    Spi_Write(0x02);                //Command for write 0x(02)
    Spi_Write(0x00);                //ar register 0x00
    Spi_Write(0x08);                //Set mode register   
    Spi_Write(0x02);                //is 16bit long           
    delay_ms(10);
    output_bit(CS_VS1011,1);                               //Hardware Reset logical level to 0-->1
    Delay_us(30);                         //attesa per l'esecuzione basta controllare lo stato di DREQ
    output_bit(CS_VS1011,0);                               //Hardware Reset logical level to 0-->1
    Spi_Write(0x02);                //
    Spi_Write(0x03);                //Set the register for the clock
    Spi_Write(0x98);                //I use a doubler PLL whit 12.288Mhz
    Spi_Write(0x00);                //
    output_bit(CS_VS1011,1);                               //Hardware Reset logical level to 0-->1
   Delay_us(30);

// ------------------------------------------------------------------- NOW IF SEE YHE VS1011  it answers
  while(!input(DREQ_VS1011) == 1);
 
     output_low(CS_VS1011);  // xCS low attiva
    delay_ms(10);
   spi_write(0x03);                                                                      //READ STATUS REGISTER
   spi_write(0x01);
   a1=spi_read();                                                                        // a1 and b1 = 0 !!!!!! <<<------ error not response
   b1=spi_read();
   delay_ms(10);
   output_high(CS_VS1011);


I set the MODE register and the clock but when I check if the VS1011 is set ok and if VS1011 response correctly , the VS1011 not response!!! a1 and b1register is set always 0 , any registry I read of VS1011!!.
The code is correct for read?
spi_write0x03); //READ STATUS REGISTER
spi_write(0x01);
a1=spi_read(); // a1 and b1 = 0 !!!!!! <<<------ error not response
b1=spi_read();
delay_ms(10);
output_high(CS_VS1011);
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Fri Feb 23, 2007 2:52 am     Reply with quote

SPI is a full duplex bus, you send and receive data at the same time. A gotcha on the CCS spi_read() function is that calling this function without parameters will return you the last received value (no SPI clock pulses are generated). If you want to receive a new byte you will have to transmit a byte simultaneously, hence pass a parameter to spi_read(). Check the VS1011 datasheet if you have to send a 0xFF or 0x00 when reading data.
Guest








PostPosted: Fri Feb 23, 2007 2:59 am     Reply with quote

ckielstra wrote:
SPI is a full duplex bus, you send and receive data at the same time. A gotcha on the CCS spi_read() function is that calling this function without parameters will return you the last received value (no SPI clock pulses are generated). If you want to receive a new byte you will have to transmit a byte simultaneously, hence pass a parameter to spi_read(). Check the VS1011 datasheet if you have to send a 0xFF or 0x00 when reading data.


Ok thanks you for your answer .

but before I must control (read) and address (register)
spi_write0x03); //READ
spi_write(0x01); //Address

then I read ....... mistake ?
Ttelmah
Guest







PostPosted: Fri Feb 23, 2007 3:24 am     Reply with quote

OK.
Once you have clocked 'out' these two bytes, you need to clcok 'in' the returned data. Clocks are only generated, when a byte is sent. So, you can either do:
Code:

   spi_write0x03); //READ
   spi_write(0x01); //Address
   //At this point, the 'read' register, will contain a garbage byte
   //clocked 'in', while the address was being transmitted.
   spi_write(0); //Clock out a _dummy_ byte to get the data back
   val=spi_read();

or:
Code:

   spi_write0x03); //READ
   spi_write(0x01); //Address
   val=spi_read(0); //This automatically clocks 'out' the dummy '0'


It is a bit of an 'annoyance', in the way the CCS SPI functions work, relative to this full duplex bus, with the spi_read function, behaving in two different ways.
Personally, I use my own SPI functions, rather than the CCS ones, since when operating in interrupt driven mode, the CCS functions do not really allow the hardware to be comfortably operated...

Best Wishes
micman2
Guest







PostPosted: Fri Feb 23, 2007 4:11 am     Reply with quote

Ttelmah wrote:
OK.
Once you have clocked 'out' these two bytes, you need to clcok 'in' the returned data. Clocks are only generated, when a byte is sent. So, you can either do:
Code:

   spi_write0x03); //READ
   spi_write(0x01); //Address
   //At this point, the 'read' register, will contain a garbage byte
   //clocked 'in', while the address was being transmitted.
   spi_write(0); //Clock out a _dummy_ byte to get the data back
   val=spi_read();

or:
Code:

   spi_write0x03); //READ
   spi_write(0x01); //Address
   val=spi_read(0); //This automatically clocks 'out' the dummy '0'


It is a bit of an 'annoyance', in the way the CCS SPI functions work, relative to this full duplex bus, with the spi_read function, behaving in two different ways.
Personally, I use my own SPI functions, rather than the CCS ones, since when operating in interrupt driven mode, the CCS functions do not really allow the hardware to be comfortably operated...

Best Wishes



Ok , Now work!!
I thought that the clock he generated it in automatic

output_low(CS_VS1011); // xCS low attiva
spi_write(0x03);
spi_write(0x01);
a1=spi_read(0);
b1=spi_read(0);
output_high(CS_VS1011); //
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