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.

74HC595 with ATmega88PA

Status
Not open for further replies.

kmdineshece

Member level 1
Member level 1
Joined
Dec 17, 2013
Messages
36
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
384
SPI Communication!///74HC595 with ATmega88Pa, my code is working perfectly in Proteus(software simulation), but it's not working in hardware!....i don't know where i did the mistake, pls guide me!...
Code:
#include <avr/io.h>
#define F_CPU 4000000UL
#include <util/delay.h>
#include <avr/interrupt.h>
#include<string.h>
#define F_CPU 8000000UL


#define SPI_PORT PORTB
#define SPI_DDR  DDRB
#define SPI_CS   PINB2
#define SPI_SCK  PINB5


//static uint8_t digits[10] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
volatile unsigned char t=0;

volatile uint8_t c=0,q,r,s,n,z=0,e,f,g,x=0,a[5];

void SPI_Write(uint8_t dataout)
{
  // Start transmission (MOSI)
  SPDR = dataout;

SPI_PORT |= (1<<SPI_SCK);

_delay_us(10);             // Hold pulse for 1 micro seconds

SPI_PORT &= ~(1<<SPI_SCK);


// Latch the Output using rising pulse to the RCK Pin
  // Wait for transmission complete
  while(!(SPSR & (1<<SPIF)));


  // Latch the Output using rising pulse to the RCK Pin
  SPI_PORT |= (1<<SPI_CS);

  _delay_us(10);             // Hold pulse for 1 micro seconds

   // Disable Latch
   SPI_PORT &= ~(1<<SPI_CS);
   // Latch the Output using rising pulse to the RCK Pin
   // Latch the Output using rising pulse to the RCK Pin
    

}

void setupSPI(void) 
{
  // Set MOSI and SCK as output, others as input
  SPI_DDR|= (1<<PINB3)|(1<<PINB5)|(1<<PINB2);

  // Latch Disable (RCK Low)
  SPI_PORT &= ~(1<<SPI_CS);

  // Enable SPI, Master, set clock rate fck/2 (maximum)
  SPCR|= (1<<SPIE)|(1<<SPE)|(1<<MSTR);
 SPSR|= (1<<SPI2X);

  
}


int main()
{
  unsigned char u8TempData;
 
  DDRC=0xff;
  
  
 	DDRD|=(1<<PIND4)|(1<<PIND5)|(1<<PIND6)|(1<<PIND7);
 
  setupSPI();
  sei();
PORTD|=(1<<PIND4);
PORTD|=(1<<PIND5);

   while(1)
    {
	 SPI_Write(((2*100)+(5*10)+(5*1)));

	 _delay_ms(1000);
		 
		 	
	 SPI_Write(((0*100)+(0*10)+(0*1)));
	  	
  _delay_ms(1000);
   }
  //return 0;
}
 

What are you trying to do?
There is no any SPI interface in "74HC595" ?


Anyway in SPI communication what is this code for
Code:
SPI_PORT |= (1<<SPI_SCK);

_delay_us(10);             // Hold pulse for 1 micro seconds

SPI_PORT &= ~(1<<SPI_SCK);
 

Hi,

Microcontroller and HC595 problems are discussed many times here. Please search the forum.
Below are links to "similar threads"

I recommend to use the AVR internal SPI periferal.

A description like "but it's not working in hardware" is useless.
You need to describe "what exactely" is not working. It could be your power supply, it could be the AVR reset circuit, it could be the AVR clock setup, bad solder joints, wiring or a lot of other things.

So first you need to test what is working correctly.
Test voltages, clock signals, and all the signal to the HC595.

Show us schematic, wiring or layout, scope pictures...

Then we soon will find and solve the problem.

Klaus
 

have you checked the final serial data output at pin No.9 in 74HC595 IC. How much sure that your hardware is not working. post the circuit diagram by using which you have made the hardware. Dont post proteus circuit.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top