Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Problem reading data from CS5460A and ATMEGA8

Status
Not open for further replies.

Alex Aldridge Arabaolaza

Newbie level 2
Joined
Jun 18, 2014
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
16
Hi mates, i'm trying to perform some measurements using a CS5460A (Cirrus Logic) microcontroller and an ATMega8 from AVR.

Here is my initialization code for the CS5460A:

Code:
#define CONFIG_REGISTER          0x40
#define CYCLE_COUNT_REGISTER 0x4A
#define STATUS_REGISTER         0x5E
#define MASK_REGISTER             0x74


void initCS5460A(){
							   
	unsigned char temp;

	CLEARBIT(PORTD, PD_RESET);	//Give CS5460 a h/w reset (PD4 = 0)
	
	SETBIT(PORTB, PB_CLCS);		// waste some time (2.9 us?)
	SETBIT(PORTB, PB_CLCS);		// waste some time (2.9 us?)
	
	SETBIT(PORTD, PD_RESET);	//
	
	//The resistor on MS_RESET will add another delay. Need to wait some us after reset pulse before starting CS5461 comms
	SETBIT(PORTB, PB_CLCS);		// waste some time (2.9 us?)
	SETBIT(PORTB, PB_CLCS);		// waste some time (2.9 us?)
	SETBIT(PORTB, PB_CLCS);	        // waste some time (2.9 us?)
	
	tm_cs5460 = 0;
        er_cs5460 = 0;

        /*This function is used whenever CS5460A is reset so each time we need to reset the following values*/
	SETBIT(ms_flags, MS_1ST_READ);   //Used to discard first read
	CLEARBIT(ms_flags, MS_CS_RESET); //Disable reset flag (it has been already done)
	CLEARBIT(tb_flags, TB_INT_LOW);	 
        
        
        //Output initialisation sequence to CS5461 via SPI
        init_CS5460A_send_sequence();
}

void init_CS5460A_send_sequence(){

    CLEARBIT(PORTB, PB_CLCS);       //Enables SPI communication

     //Resync
    cs5460_send(0xFF);
    cs5460_send(0xFF);
    cs5460_send(0xFF);
    cs5460_send(0xFE);
    
    //soft reset
    cs5460_Write_data(CONFIG_REGISTER, 0x000080);

    
    //Resync
    cs5460_send(0xFF);
    cs5460_send(0xFF);
    cs5460_send(0xFF);
    cs5460_send(0xFE);
    
    //configure (x10 gain for current)
    cs5460_Write_data(CONFIG_REGISTER, 0x000061);
    
    //set integration period (72 clocks)
    cs5460_Write_data(CYCLE_COUNT_REGISTER, 0x000048);

     //reset all bits in status register (IC* bit ignored)
     cs5460_Write_data(STATUS_REGISTER, 0xFFFFF);

    
     //set DRDY in mask register (for INT*)
     cs5460_Write_data(MASK_REGISTER, 0x800000);

    
    //start continuous computation cycles
    cs5460_send(0xE8);
    
    SETBIT(PORTB, PB_CLCS);         //Disables SPI communication

}

After that, I try to perform some reads but the program seems to hang (it should light a LED after 20 seconds but it never lights)

This is my code to perform a read:

Code:
void cs5460_sync(){
	
	/*This functions sends the init sequence that the CS5460A needs to start operating*/
	unsigned char sync_sequence[] = {0xFF, 0xFF, 0xFF, 0xFE};
	unsigned char iterator = 0;
	
	for (iterator = 0; iterator < 4; iterator++){
		
		cs5460_send(sync_sequence[iterator]);
	}
}




unsigned long int cs5460_Read_data(char cData)
{
  char spi_data1=0,spi_data2=0,spi_data3=0;
  /* Start transmission */
  cs5460_sync();
  SPDR = cData;
  /* Wait for transmission complete */
  while(!(SPSR & (1<<SPIF)))
  spi_data3=SPDR;
  SPDR = 0xff;
  while(!(SPSR & (1<<SPIF)))
  spi_data3=SPDR;
  SPDR = 0xff;
  while(!(SPSR & (1<<SPIF)))
  spi_data2=SPDR;
  SPDR = 0xff;
  while(!(SPSR & (1<<SPIF)))
  spi_data1=SPDR;

  
  return (0x00FFFFFF & (((spi_data3*65536) & 0x00FF0000)|((spi_data2<<8) & 0x0000FF00)|(spi_data1& 0x000000FF)));
}



Do you have any idea of what could be wrong here?

Thanks in advance,

ALex
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top