Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

Re: [AVR-Chat] Help with bit banged spi

2013-11-27 by bobgardner@aol.com

//---external mc3204 12 bit spi a/d converter
#define CLKHI() PORTB |=  0x80
#define CLKLO() PORTB &= ~0x80
#define CLKPULSE() CLKHI(); CLKLO()

#define DATHI() PORTB |=  0x40
#define DATLO() PORTB &= ~0x40

#define STARTBIT() DATHI(); CLKPULSE()
#define  STOPBIT() DATLO(); CLKPULSE()

#define DDRB6OUT() DDRB |=  0x40
#define DDRB6IN()  DDRB &= ~0x40

#define CSHI() PORTB |=  0x10
#define CSLO() PORTB &= ~0x10

//-----------------------------------------
void bbout8(unsigned char dat){
//shift 8 bits of dat out pb6 lsb 1st
//clk=pb7 dat=pb6 cs=pb4
//seems to be about half as fast as the double speed spi version
unsigned char i,msk,bit;

  DDRB6OUT(); 
	STARTBIT();            
	msk=0x01; 
	for(i=0; i<8; i++){              //for n bits
  bit=(dat & msk) != 0;          //extract bit from dat
		  if(bit) DATHI(); else DATLO(); //put it in the port
		  CLKPULSE();                    //shake the clock
		  msk <<= 1;                     //ready for next bit
	}
	STOPBIT();
}

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.