前几天发现:仓库里有一堆库存的 ATMEL AT93C66, 能做啥呢?
先把之前 51上的码拿来改改, 哪天那个PM心血来潮, 会有点赶(去声) 。
Re-Structure for covering Microchip (ATMEL) AT93C46/56/66
2022/09/18
- Support AT93C46/56/57/66.
- Support Timeout scheme. by SystTick.
Example Usage:
RESULTS_Typedef xAT93Cx6Test( uint16_t address, uint16_t uiData)
{
uint16_t uiTemp=0;
uint16_t uiReadBack=0;
#if 8 == DATA_SIZE
uiData &= 0x00FF;
#endif
/* Init Bus */
vAT93Cx6Init( );
if ( FAIL == bAT93Cx6BusyCheck( ))
{
printf("\nDevice Error / MISO = Low " );
retrun FAIL;
}
// Backup Data
uiTemp = uiAT93Cx6Read( uiAddress );
// Write Data into EEPROM
uiAT93Cx6Write( address, uiData );
// Read Back for compare
uiReadBack = uiAT93Cx6Read(uiAddress);
// Write original data Back
uiAT93Cx6Write( address, uiTemp );
// Compare Data
if( uiData != uiReadBack )
{
printf("\nCompare Error %04X,%04X", uiData , uiReadBack );
return FAIL;
}
return PASS;
}
AT93Cx6.H
/***************************************************************************
* AT93Cx6.H
* Microchip (ATMEL) AT93C46/56/57/66 SPI EEPROM
*
* 2022/09/18 By Jason Lu.
*
* It is a SINGLE BYTE/WORD access only. No automatic address increment like
* AT24Cxx. Do'not support multiple length access.
*
* Hardware:
* 1. Make sure device type
* 2. Choose ORG level for 8/16 bits data access.
* ( ORG Gnd: 8bits, ORG High: 16bits)
*
* Configuration Method:
* 0. Set Hardware Control pin address & Connection
* 1. Set Device AT93C46, 56, 57, 66
* 2. Set DATA_SIZE 8bits, 16bits Related to hardware ORG pin State
* 3. Implment DelayPeriod() Clock high/low period, excluding data process
* 4. Implment ulGetSystemTick() as 1ms tick for timeout check.
*
* Example usage:
*
* Initialize Bus state for Access
* vAt93cx6Init( );
*
* Read Data
* #if 8 == DATA_SIZE
* ucData = (uint8_t) uiAT93Cx6Read( uiAddress );
* #endif
* #if 16 == DATA_SIZE
* uiData = uiAT93Cx6Read( uiAddress );
* #endif
*
* Write data
* uiAT93Cx6Write( address, uiData );
*
*/
#ifndef __AT93CX6_H_
#define __AT93CX6_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "stm32f1xx_hal.h"
typedef enum { PASS=0, FAIL=!PASS } RRESULTS_Typedef;
/* Set Device */
//#define AT93C46
//#define AT93C57
//#define AT93C56
#define AT93C66
/* Data Size 8bits(ORG Low) / 16 bits(ORG high) */
#define DATA_SIZE 16
#if (!defined AT93C46)&&(!defined AT93C57)&&(!defined AT93C56)&&(!defined AT93C66 )
#define AT93C66
#endif
/* Set EEPROM Size 1024/2048/4096 */
#ifdef AT93C46
#define EEPROM_SIZE 1024
#endif
#ifdef AT93C57
#define EEPROM_SIZE 2048
#endif
#ifdef AT93C56
/* Setting for Address Length calculation -> Dummy A8 clock */
#define EEPROM_SIZE 4096
#endif
#ifdef AT93C66
#define EEPROM_SIZE 4096
#endif
#if 64 == (EEPROM_SIZE / DATA_SIZE)
#define ADDRESSLENGTH 6
#endif
#if 128 == (EEPROM_SIZE / DATA_SIZE)
#define ADDRESSLENGTH 7
#endif
#if 256 == ( EEPROM_SIZE / DATA_SIZE )
#define ADDRESSLENGTH 8
#endif
#if 512 == (EEPROM_SIZE / DATA_SIZE)
#define ADDRESSLENGTH 9
#endif
#ifdef __STM32F1xx_HAL_H
//provide 1ms System tick for time-out measurement
#define ulGetSystemTick() HAL_GetTick()
/* Clock Pulse Period */
extern void DelayXus(uint32_t);
#define DelayPeriod() DelayXus(2)
#define hwAT93Cx6CS ( 1U << 12 )
#define portResetAT93Cx6CS() ( GPIOB->BRR = hwAT93Cx6CS )
#define portSetAT93Cx6CS() ( GPIOB->BSRR = hwAT93Cx6CS )
#define hwAT93Cx6MOSI ( 1U << 14 )
#define portResetAT93Cx6MOSI() ( GPIOB->BRR = hwAT93Cx6MOSI )
#define portSetAT93Cx6MOSI() ( GPIOB->BSRR = hwAT93Cx6MOSI )
#define portGetAT93Cx6MOSI() ( GPIOB->IDR & hwAT93Cx6MOSI )
#define hwAT93Cx6MISO ( 1U << 15 )
//#define portResetAT93Cx6MISO() ( GPIOB->BRR = hwAT93Cx6MISO )
#define portSetAT93Cx6MISO() ( GPIOB->BSRR = hwAT93Cx6MISO )
#define portGetAT93Cx6MISO() ( GPIOB->IDR & hwAT93Cx6MISO )
#define IS_DEVICE_BUSY( ) ( 0 == portGetAT93Cx6MISO())
#define hwAT93Cx6CK ( 1U << 13 )
#define portResetAT93Cx6CK() ( GPIOB->BRR = hwAT93Cx6CK )
#define portSetAT93Cx6CK() ( GPIOB->BSRR = hwAT93Cx6CK )
#else
//provide 1ms System tick for time-out measurement
extern uint32_t ulGetSystemTick();
/* Clock Pulse Period */
#define DelayPeriod() { _nop_(); _nop_(); _nop_();}
sbit hwAT93Cx6CS = 0xB3;
#define portResetAT93Cx6CS() hwAT93Cx6CS=0
#define portSetAT93Cx6CS() hwAT93Cx6CS=1
sbit hwAT93Cx6MOSI = 0xB4;
#define portResetAT93Cx6MOSI() hwAT93Cx6MOSI=0
#define portSetAT93Cx6MOSI() hwAT93Cx6MOSI=1
#define portGetAT93Cx6MOSI() hwAT93Cx6MOSI
sbit hwAT93Cx6MISO = 0xB5;
//#define portResetAT93Cx6MISO() hwAT93Cx6MISO=0
#define portSetAT93Cx6MISO() hwAT93Cx6MISO=1
#define portGetAT93Cx6MISO() hwAT93Cx6MISO
#define IS_DEVICE_BUSY( ) ( 0 == portGetAT93Cx6MISO())
sbit hwAT93Cx6CK = 0xB7;
#define portResetAT93Cx6CK() hwAT93Cx6CK=0
#define portSetAT93Cx6CK() hwAT93Cx6CK=1
#endif
/***************************************************************************
* Function : bAT93Cx6BusyCheck(void)
* Description : Check DO Busy State
* Parameter(s): n/a
* Return : PASS or FAIL= Timeout > 10ms
*/
RRESULTS_Typedef bAT93Cx6BusyCheck(void);
/***************************************************************************
* Function : uiAT93Cx6Writed()
* Description : Write Byte/Word
*/
void uiAT93Cx6Write( uint16_t , uint16_t );
/***************************************************************************
* Function : uiAT93Cx6Read()
* Description : Read Byte/Word
*/
uint16_t uiAT93Cx6Read(uint16_t );
/***************************************************************************
* Function : vAT93Cx6Init(void)
* Description : Init SPI Bus Pin State
*/
void vAT93Cx6Init(void);
#ifdef __cplusplus
}
#endif
#endif
Download: Code Package STM32_AT93Cx6 Lib.zip
Microchip (ATMEL) AT93C66 Re-Structure for covering AT93Cx6
<备份> 收集资料, 仅供参考。
数据剪辑自原厂规格书, 版权归原所有人拥有。
档案取自互联网!如有侵权或不适用情形, 请联系移除!
** 使用有风险, 请详阅原厂使用说明!
** 范例码为自用,请谨慎引用, Ctrl-C, Ctrl-V结果自行承担!
#Blog转移
#电子零件