[General] 93c46b interfacing with R8C2B7

Status
Not open for further replies.

sp2012

Junior Member level 3
Joined
Mar 20, 2012
Messages
25
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Banglore
Activity points
1,512
Hi to all,

Here i am using 93C46B microwire serial eeprom.
Now i can able to write and read only 2 bytes.
I cant write more then 2 bytes and read also?
Here i shared my code.please check it and guide me to solve this.



#define EE_CS p3_4 // op
#define EE_DI p3_3 // op
#define EE_CLK p3_5 // op
#define EE_DO p3_7 // ip

#define TRUE 1
#define FALSE 0
unsigned int cnt;
unsigned char read_data[20];
unsigned char HiByte; //High Order Byte
unsigned char LoByte; //Low Order Byte
unsigned char HiData; //Hi Data Byte (upper 8 bits of word)
unsigned char LoData; //Lo Data Byte (lower 8 bits of word)
unsigned char ReadData[25]; //Holds Device data being read back
unsigned char Length; //Number of Bytes to read (2 for x16 mode)

void delay(unsigned int dly);
void Delay_Ms(unsigned int dly);


void Delay_Ms(unsigned int dly)
{
unsigned int cnt;
while(dly--)
{
cnt=20;
while(cnt--);
}
}

void delay(unsigned int dly)
{
while(dly--);
}


/********************************************************************
* Function Name: WriteMwire *
* Return Value: Status byte for WCOL detection. *
* Parameters: Single data byte for SPI bus. *
* Description: This routine writes a single byte to the *
* Mwire bus. *
********************************************************************/
unsigned char WriteMwire( unsigned char data_out )
{
unsigned char Count;
for(Count=0;Count<8;Count++)
{
if((data_out&0x80)==0x80)
EE_DI = 1; //check BIT7 & out data
else
EE_DI = 0;
delay(100);
EE_CLK = 1; //clock high
delay(10);
EE_CLK = 0; //clock low
data_out=data_out<<1; //shift one bit to left
}


}

/********************************************************************
* Function Name: EWEN *
* Return Value: void *
* Parameters: void *
* Description: This routine sets the Write Enable Latch *
********************************************************************/

void EWEN (void)
{
EE_CS = 1; //Select Device
WriteMwire ( 0x04 ); //EWEN Command
WriteMwire ( 0xC0 ); //for 4K Microwire
EE_CS = 0; //Deselect Device
}

/********************************************************************
* Function Name: getsMwire *
* Return Value: void *
* Parameters: address of read string storage location and *
* length of string bytes to read *
* Description: This routine reads a string from the *
* Microwire device. User must first issue *
* start bit, opcode and address before reading*
* a string. *
********************************************************************/
void getsMwire( unsigned char *rdptr, unsigned char length )
{
unsigned char data, Count, temp=0;
cnt=0;
while( length )
{
data=0;
for(Count=0;Count<8;Count++)
{
EE_CLK = 1; //clock high
data=data<<1;
delay(100);
temp=EE_DO;

/* if (EE_DO)
data=data|0x01; //read MISO pin
else
data &= 0xfe;*/
data |= EE_DO;

EE_CLK = 0;
}
*rdptr++ = data;
length--;
}
}
/********************************************************************
* Function Name: DataRdyMwire *
* Return Value: status byte to indicate ready/busy *
* Parameters: void *
* Description: Determine if Microwire device is ready, *
* write cycle complete. *
********************************************************************/
unsigned char DataRdyMwire( void )
{
if(EE_DO)
return ( 1 );
else
return ( 0 );
}
/********************************************************************
* Function Name: EWDS *
* Return Value: void *
* Parameters: void *
* Description: This routine sets the Write Enable Latch *
********************************************************************/

void EWDS (void)
{
EE_CS = 1; //Select Device
WriteMwire ( 0x04 ); //EWDS Command
WriteMwire ( 0x00 ); //for 4K Microwire
EE_CS = 0; //Deselect Device
}
/********************************************************************
* Function Name: x16ByteWrite *
* Parameters: EE memory control, address and data *
* Description: Writes Data Byte to Mwire EE memory device *
* Can be used with any Microwire in X16 mode *
* HiByte and LoByte will need to be modified *
* for alignment of Op Code *
********************************************************************/
unsigned char x16ByteWrite(unsigned char HiByte, unsigned char LoByte, unsigned char HiData, unsigned char LoData )
{
EE_CS = 1; // Select Device
WriteMwire ( HiByte ); // Send HiByte (Dummy bits, SB, and Op Code)
WriteMwire ( LoByte ); // Send LoByte (Address for the 93LC66C)
WriteMwire ( HiData ); // Send HiData to EEPROM
WriteMwire ( LoData ); // Send LoData to EEPROM

EE_CS = 0;
EE_CS = 1;
while (!DataRdyMwire()); // Wait for Write to complete
EE_CS = 0;
delay(1000);
return ( 0 );

}

/********************************************************************
* Function Name: x16ByteRead *
* Parameters: EE memory control, address, pointer and *
* length bytes. *
* Description: Reads two data bytes from the Microwire *
* device. Can be used for any Microwire in *
* x16 mode. Hibyte and Lobyte will need to *
* modified for alignment of Op Code *
********************************************************************/
unsigned char x16ByteRead(unsigned char HiByte, unsigned char LoByte, unsigned char *ReadData, unsigned char Length )
{
EE_CS = 1; // Select Device
WriteMwire ( HiByte ); // Send Read OpCode
WriteMwire ( LoByte ); // WRITE word address to EEPROM
getsMwire ( ReadData, Length); // Reads two bytes for x16 word
EE_CS = 0; // Deselect Device
return ( 0 );
}
void app_main(void)
{
int n;

HiByte = 0x05; //Dummy Zero's, Start Bit and Op Code for Byte Write
LoByte = 0x00; //Address bits for 93LC66C
HiData = 0x32; //Upper 8 bits of Data word
LoData = 0x50; //Lower 8 bits of Data word
Length = 15; //Number of bytes to read (2 for x16) (1 for x8)

EWEN (); //Erase/Write Enable
x16ByteWrite (HiByte, LoByte, HiData, LoData);
EWDS (); //Erase/Write Disable

HiByte = 0x06; //Changes //OpCode from Write to Read for next function
x16ByteRead (HiByte, LoByte, ReadData, Length);

asm("nop");
while (1){}; //Loop here forever

}
 

Attachments

  • microchip-93LC46.pdf
    344.1 KB · Views: 41

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…