93 C 46 App 2310

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Hitachi Europe Ltd. ISSUE : app023/1.

APPLICATION NOTE DATE 20/9/94

93C46 CMOS Serial Electrically Erasable PROM


This Routine has been written to interface to a SGS 93C46A Serial EEROM, in word mode, from a H8-325
Microcontroller. Although based on the 325 device, it can easily be adapted to other H8-300 members.

The method of communication is by bit manipulation of i/o ports to produce a clock, data output, CE and to
read data i/p. Four port lines are used and the pin assignment is as follows:-

P70 - CE,
P55 - SK,
P61 - DI,
P62 - DO.

A summary of the function of each routine is as follows:-

1.0 WREN - writes an 8 bit command to enable writing to the 93C46.


Passed - void.
Return - void.

2.0 WRDIS - writes an 8bit command to disable writing to the 93C46.


Passed - void.
Return - void.

3.0 WRITE - writes a 16bit data word to a specified address.


Passed - unsigned int data, unsigned char address.
Return - void.

4.0 READ - Reads a 16bit data word from a specified address.


Passed - unsigned char address.
Return - unsigned int data.

5.0 CHK_SUM - reads and sums the first 17 locations. The summed value is
compared to the checksum value stored in location 63. If in error
a '1' is returned else a '0'. The 17 locations are summed with a
fixed seed value of 0xAA55.
Passed - void.
Return - unsigned char error flag.

6.0 Write_Delay - produces an 11 .78ms delay for a crystal frequency of 12MHz.


Passed - void.
Return - void.

7.0 STO - This calculates and writes a new checksum. Once written further
writes are disabled.
Passed - void.
Return - void.

8.0 Serial_Write_8 - writes 8 bit data to 93C46.


Passed - unsigned char data.
Return - void.

9.0 Serial_Write_16 - writes 16 bit data to 93C46.


Passed - unsigned int data.
Return - void.

1 of 6
Hitachi Europe Ltd. ISSUE : app023/1.0

10.0 Serial_Read_16 - reads 16 bit data from 93C46.


Passed - void.
Return - unsigned int data.

The order in which the routines should be called are as follows:-

Write - 1.0 WREN()


2.0 WRITE() - as required.
3.0 STO().

Read - 1.0 READ() - as required.

/* PRE-PROCESSOR DIRECTIVES AND DEFINITIONS */

#include "ioh8325.h"

#define BIT00 0x0001


#define BIT01 0x0002
#define BIT02 0x0004
#define BIT03 0x0008
#define BIT04 0x0010
#define BIT05 0x0020
#define BIT06 0x0040
#define BIT07 0x0080
#define BIT08 0x0100
#define BIT09 0x0200
#define BIT10 0x0400
#define BIT11 0x0800
#define BIT12 0x1000
#define BIT13 0x2000
#define BIT14 0x4000
#define BIT15 0x8000

#define M9346_CE_CLEAR P7DR&=~BIT00


#define M9346_CE_SET P7DR|=BIT00

#define M9346_SK_CLEAR P5DR&=~BIT05


#define M9346_SK_SET P5DR|=BIT05

#define M9346_DI_SET P6DR|=BIT01


#define M9346_DI_CLEAR P6DR&=~BIT01

/*-----------------------------------------------------------

Function Prototypes
-----------------------------------------------------------*/

void WREN(void);
void WRDIS(void);
void WRITE(unsigned int num,unsigned char addr);

2 of 6
Hitachi Europe Ltd. ISSUE : app023/1.0
unsigned char CHK_SUM(void);
unsigned int READ(unsigned char addr);
void Write_Delay(void);
void STO(void);
void Serial_Write_8(unsigned char Data);
void Serial_Write_16(unsigned int Data);
unsigned int Serial_Read_16(void);

/*-----------------------------------------------------------*/

void WREN(void)
/*
Routine to enable writing to the 93C46

*/
{
unsigned char x=0;
Serial_Write_8(0x30); /* EWEN instruction */
for(x=0; x<=2; x++); /* delay of 25us */
M9346_CE_CLEAR;
}

void WRDIS(void)
/*
Routine to disable writing to the 93C46

*/
{
unsigned char x=0;

Serial_Write_8(0x00); /* EWDIS instruction */


for(x=0; x<=2; x++);
M9346_CE_CLEAR;
}

void WRITE(unsigned int num,unsigned char addr)


/*
Routine to write an integer to a set address in the
93C46.

*/
{
unsigned char x=0;

Serial_Write_8(0x40 | addr); /* send write address */


for(x=0; x<=2; x++);
Serial_Write_16(num); /* send hi byte */
for(x=0; x<=2; x++);
M9346_CE_CLEAR; /* cs low */
Write_Delay();

unsigned int READ(unsigned char addr)

3 of 6
Hitachi Europe Ltd. ISSUE : app023/1.0
/*

Routine to read an integer from a given address.

*/
{

unsigned char x;
unsigned int num;

Serial_Write_8(0x80 | addr); /* send read command */


for(x=0; x<=2; x++);
num=Serial_Read_16();
for(x=0; x<=2; x++);
M9346_CE_CLEAR; /* cs low */
return(num);
}

unsigned char CHK_SUM(void)


/*
Routine to check the contents of the 93C46 for the correct
checksum.
*/
{
unsigned int x,tword,word=0xAA55;

for(x=0; x<=16; x++) word+=READ(x); /* sum 17 words */


tword=READ(63);
return (word != tword) ? 1 : 0; /* Checksum error flag */
}

void Write_Delay(void)
{
unsigned int x;
for (x=0;x<2000;x++); /* 11.78ms delay */
}

void STO(void)
/*

Writes new checksum value and then disables any further writes.

*/
{
unsigned int num = 0xAA55;
unsigned char x;

for(x=0; x<=16; x++) num+=READ(x); /* Calculate new checksum */

/* write new checksum */

Serial_Write_8(0x40 | 63); /* send write address - note checksum is


stored in location 63 */
for(x=0; x<=2; x++);
Serial_Write_16(num); /* send data */
for(x=0; x<=2; x++);
M9346_CE_CLEAR; /* cs low */

4 of 6
Hitachi Europe Ltd. ISSUE : app023/1.0
Write_Delay();

WRDIS(); /* disable further writes */


}

void Serial_Write_8(unsigned char Data)


{
unsigned char x,y;

M9346_CE_SET;
M9346_DI_SET;
M9346_SK_SET; /* send start bit */
for(x=0; x<=2; x++);
M9346_SK_CLEAR;

for (x=0;x<8;x++)
{

if (Data&0x80)

M9346_DI_SET;
else
M9346_DI_CLEAR;

M9346_SK_SET;
for(y=0; y<=2; y++);
M9346_SK_CLEAR;

Data*=2;
}

void Serial_Write_16(unsigned int Data)


{
unsigned char x,y;
unsigned int z;

for (x=0;x<16;x++) /* for 16 bits */


{
z = Data>>15; /* MSBit first */

if (z)
M9346_DI_SET;
else
M9346_DI_CLEAR;

M9346_SK_SET;
for(y=0; y<=2; y++); /* clock high time */
M9346_SK_CLEAR;

Data*=2; /* next bit */


}

unsigned int Serial_Read_16(void)


{
unsigned char x;

5 of 6
Hitachi Europe Ltd. ISSUE : app023/1.0
unsigned int Data=0;

for (x=0;x<16;x++)
{
Data*=2;

M9346_SK_SET; /* clock high */

Data|=(P6DR>>2)&BIT00; /* read data */

M9346_SK_CLEAR; /* clock low */

return(Data);

When using this document, keep the following in mind,

1, This document may, wholly or partially, be subject to change without notice.


2, All rights are reserved: No one is permitted to reproduce or duplicate, in any form, the whole or part of this document without Hitachi’s
permission.
3, Hitachi will not be held responsible for any damage to the user that may result from accidents or any other reasons during the operation
of the user’s unit according to this document.
4, Circuitry and other examples described herein are meant only to indicate the characteristics and performance of Hitachi’s semiconductor
products. Hitachi assumes no responsibility for any intellectual property claims or other problems that may result from applications based
on the examples therein.
5, No license is granted by implication or otherwise under any patents or other rights of any third party or Hitachi, Ltd.
6, MEDICAL APPLICATIONS: Hitachi’s products are not authorised for use in MEDICAL APPLICATIONS without the written
consent of the appropriate officer of Hitachi’s sales company. Such use includes, but is not limited to, use in life support systems. Buyers
of Hitachi’s products are requested to notify the relevant sales office when planning to use the products in MEDICAL APPLICATIONS.

Copyright Hitachi, Ltd.,1994. All rights reserved

6 of 6

You might also like