View previous topic :: View next topic |
Author |
Message |
Justy
Joined: 28 Jan 2004 Posts: 6 Location: Montr�al
|
Spi communication from Pic 16F877 to an EEprom |
Posted: Wed Jan 28, 2004 2:04 pm |
|
|
Is there any C program that someone has that i can look with my program because i've tried many things an i'm out of idea. I just want to send some data in and read it out from hyperterminal by using rs232. What i want to do with this program is to be able to send an 8bit sound into my memory.
please help !!!!! |
|
|
chava
Joined: 07 Sep 2003 Posts: 56
|
is the eeprom is SPI? |
Posted: Wed Jan 28, 2004 2:18 pm |
|
|
As far as I know EEPRON uses I2C protocol, isnt it?
what kind of eepron do you have? |
|
|
Justy
Joined: 28 Jan 2004 Posts: 6 Location: Montr�al
|
|
Posted: Wed Jan 28, 2004 2:24 pm |
|
|
My eeprom is AT25HP512
It's an Spi serial eeprom. |
|
|
snoopy Guest
|
|
Posted: Wed Jan 28, 2004 4:52 pm |
|
|
Are you Take care of SPI configuration?
setup_spi(SPI_MASTER | SPI_H_TO_L | SPI_CLK_DIV_4);
What is the SPI comm speed of your Atmel?
It miss to much detail to help you. |
|
|
neil
Joined: 08 Sep 2003 Posts: 128
|
memory v protocol |
Posted: Wed Jan 28, 2004 5:57 pm |
|
|
The EEPROM is a type of memory, I2C is a communication protocol. EEPROM can have any interface the manufacturer chooses to give it. 93Cxx series are SPI, 24Cxx are I2C. There are other types as well, parallel, etc. |
|
|
dvsoft
Joined: 28 Nov 2003 Posts: 46
|
|
Posted: Thu Jan 29, 2004 10:58 am |
|
|
Hello,
I use a " AT45DB321B " and I never succeeded with used routines SPI of compiler CCS?
Therefore I use the functions C following
//----------------------------------------------------------------------------
// DTF_PINS
//
#define DTF_CLK PIN_C3 // DTF Pin Clock
#define DTF_SO PIN_C4 // DTF Pin Sortie SPI de la DataFlash
#define DTF_SI PIN_C5 // DTF Pin Entree SPI de la DataFlash
#define DTF_READY PIN_E1 // DTF Pin Ready
#define DTF_CS PIN_E2 // DTF Pin Chip select
//----------------------------------------------------------------------------
// DTF MACRO
//
#define DTF_SELECT() output_low(DTF_CS)
#define DTF_UNSELECT() output_high(DTF_CS)
#define DTF_IS_READY() (input(DTF_READY))
//----------------------------------------------------------------------------
// TRIS
//
#define TRIS_E 0b00000010 // Tris du port E
#define TRIS_C 0b10010110 // Tris du port C
//----------------------------------------------------------------------------
// Fast IO
//
#USE fast_io(E)
#USE fast_io(C)
//----------------------------------------------------------------------------
void write_SPI(BYTE Shift)
{
BYTE BitCnt = 8;
//--- Shifts out
do {
//--- Clock low
output_low(DTF_CLK);
//--- Bit = 1
if(Shift & 0x80)
output_high(DTF_SI);
//--- Bit = 0
else
output_low(DTF_SI);
Shift <<= 1;
//--- Clock high
output_high(DTF_CLK);
} while (--BitCnt);
}
//----------------------------------------------------------------------------
BYTE read_SPI()
{
BYTE Shift,BitCnt = 8;
//--- Shift in
do {
//--- Clock Low, high
output_low(DTF_CLK);
output_high(DTF_CLK);
Shift <<= 1;
//--- Bit = 0
if(!input(DTF_SO))
Shift &= ~1;
//--- Bit = 1
else
Shift |= 1;
} while (--BitCnt);
return (Shift);
}
PIC18F452 Cristal 10Mz+PLL
CCS compiler 3.184 |
|
|
Justy
Joined: 28 Jan 2004 Posts: 6 Location: Montr�al
|
ITS WORKING :D |
Posted: Thu Jan 29, 2004 12:38 pm |
|
|
I would like to thank you guys, specially Neil for the help that you gave to my partner Spiffy . The command SPI_read(0); was a really big piece of the puzzle but we've also noticed that we had to bring the chip select low, enter the write enable op-code and then bring it back high again. After that we had to bring it back low and send the write op-code, adress and data before bringing it back high again. that`s the right way to do it which wasn't explained properly in the datasheet.
Anyways it works perfectly now and i'm going to give y'all the final program:
#include "16f877.h"
#include "stdlib.h"
#use delay (clock=4000000)
#use rs232 (baud=9600,xmit=pin_c6,rcv=pin_c7)
#bit CKE = 0x94.6
#bit SMP = 0x94.7
#bit CKP = 0x14.4
#byte SSPSTAT=0x94
#byte SSPCON=0x14
//D�claration des variables
char choix;
int data=0,yx;
long int i=0;
void ecriture (void);
void lecture (void);
void main (void)
{
set_tris_C(0x90); //configure les ports pour sortie et entree.
set_tris_A(0x00);
set_tris_E(0x04);
setup_spi(spi_master|spi_l_to_h|spi_clk_div_16);
CKE = 1; // donn�e VALIDE de front descendant � front descendant
CKP = 0; // La m�moire �chantillone sur front montant
SMP = 0; // �chantillonage au centre d'un cr�neau
while(1)
{
i=0;
Printf("\n\r1 pour activer l'�criture ou 2 pour la lecture");
choix=getch();
if (choix=='1')
{
ecriture();
}
if (choix=='2')
{
lecture();
}
else
{
puts("\n\r Erreur");
}
}
}
void ecriture (void)
{
printf("\n\r SSPSTAT:%x",SSPSTAT);
printf("\n\r SSPSTAT:%x",SSPCON);
printf("\n\r appuyer sur UN chiffre:");
yx=getch();
printf("\n\rlecture:%d",yx);
getch();
delay_ms(45);
output_low(pin_a4); //On choisi la memoire
spi_write(0x06); //Write enable
output_high(pin_a4);
output_low(pin_a4);
spi_write(0x02); //on veut ecrire sur la memoire
spi_write(0x00);
spi_write(0x00); //On choisi l'adress
spi_write(yx); //On designe le data a envoyer
output_high(pin_a4); //On enleve la selection de memoire
delay_ms(200);
printf("\n\r ok!");
}
void lecture (void)
{
printf("\n\r SSPSTAT:%x",SSPSTAT);
printf("\n\r SSPSTAT:%x",SSPCON);
printf("\n\rReading...");
output_low(pin_a4);
spi_write(0x03);
spi_write(0x00);
spi_write(0x00);
delay_ms(23);
While(i<10)
{
data=spi_read(0);
printf("\n\rlecture: %lu %x",i,data);
i++;
}
output_high(pin_a4);
} |
|
|
|