AnsweredAssumed Answered

AD 420 interfacing with ATTiny 2313

Question asked by askindia on May 15, 2012
Latest reply on May 28, 2012 by MCollins

Dear All,

 

This is gaurav. I am trying to interface Atmel's  Attiny 2313 with the ad420, i have tried all the code snippets which are available on the net but not able to get success. Please guide us on the issue as deadlines are smiling at us. We have to deliver 50 devices  based on this concept within fortnight.

 

#define F_CPU 8000000UL 
  
 #define DATAOUT PB6 
 #define CLOCK PB7 
 #define LATCH PA1 
  
  
 void setup_SPI(void) { 
   
   // USI stuff 
   
    DDRB |= (1<<CLOCK)|(1<<DATAOUT); 
    DDRA |= (1<<LATCH);    
  
  
 } 
  
  
 uint8_t spi_transfer(uint8_t data) { 
   
   #if 1 //This is asynchronous mode with AD420 
  
   int ibitspos=7; 
   int ibitarr[8]={0}; 
   
   cbi(PORTA,LATCH); 
   cbi(PORTB,CLOCK); 
   
   cbi(PORTB,DATAOUT); //START BIT for AD420 
   sbi(PORTB,CLOCK);  //Rising Edge Data Send 
   _delay_us(1); 
   cbi(PORTB,CLOCK); 
     
   for(;ibitspos>=0;ibitspos--){ 
    ibitarr[(7-ibitspos)] = (/*0x40 &*/ ((data&(1<<ibitspos)>>ibitspos))); 
    if(ibitarr[(7-ibitspos)]){ 
       sbi(PORTB,DATAOUT); 
       SendData('P'); 
    }    
    else{ 
       cbi(PORTB,DATAOUT); 
       SendData('N'); 
    }    
     _delay_us(1); 
    sbi(PORTB,CLOCK); 
    _delay_us(1); 
    cbi(PORTB,CLOCK); 
   } 
   
   sbi(PORTB,DATAOUT);//STOP BIT 
   sbi(PORTB,CLOCK); 
   _delay_us(1); 
   cbi(PORTB,CLOCK); 
   
   sbi(PORTA,LATCH);      
   _delay_us(100); 
   cbi(PORTA,LATCH);         
   for(ibitspos=0;ibitspos<8;ibitspos++) 
    SendData(ibitarr[ibitspos]+0x30); 
 #else 
   USIDR = data; 
   USISR = _BV(USIOIF); // clear fla
  
   while ((USISR & _BV(USIOIF)) == 0) { 
    USICR = (1<<USIWM0)|(1<<USICS1)|(1<<USICLK)|(1<<USITC); 
   } 
   return USIDR; 
 #endif    
  
 } 

 

regards,

gaurav holey

askindia

Outcomes