hello
This commit is contained in:
parent
db141c586d
commit
e9e6d9df75
42
AT24CSW.c
Normal file
42
AT24CSW.c
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* AT24CSW.c
|
||||
*
|
||||
* Created on: Nov 12, 2021
|
||||
* Author: angoosh
|
||||
*/
|
||||
|
||||
|
||||
#include "AT24CSW.h"
|
||||
#include "main.h"
|
||||
|
||||
extern I2C_HandleTypeDef AT24CSW_I2C_HANDLE;
|
||||
|
||||
int AT24CSW_Read_Memory(uint8_t address, uint8_t size, uint8_t *data);
|
||||
int AT24CSW_Page_Write(uint8_t address, uint8_t *bytes);
|
||||
int AT24CSW_Byte_Write(uint8_t address, uint8_t byte);
|
||||
|
||||
int AT24CSW_Byte_Write(uint8_t address, uint8_t byte){
|
||||
uint8_t data[2] = {address,byte};
|
||||
HAL_I2C_Master_Transmit(&AT24CSW_I2C_HANDLE, (AT24CSW_ADDRESS << 1), data, 3, 0xFFFF);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AT24CSW_Page_Write(uint8_t address, uint8_t *bytes){
|
||||
uint8_t data[9];
|
||||
data[0] = address;
|
||||
for(int i = 0; i < 8; i++){
|
||||
data[i+1] = bytes[i];
|
||||
}
|
||||
HAL_I2C_Master_Transmit(&AT24CSW_I2C_HANDLE, (AT24CSW_ADDRESS << 1), data, 3, 0xFFFF);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AT24CSW_Read_Memory(uint8_t address, uint8_t size, uint8_t *data){
|
||||
uint8_t memContent[256];
|
||||
HAL_I2C_Master_Receive(&AT24CSW_I2C_HANDLE, (AT24CSW_ADDRESS << 1), memContent, 0xFF, 0xFFFF);
|
||||
|
||||
for(int i = 0; i < size; i++){
|
||||
data[i] = memContent[address+i];
|
||||
}
|
||||
return 0;
|
||||
}
|
30
AT24CSW.h
Normal file
30
AT24CSW.h
Normal file
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* AT24CSW.h
|
||||
*
|
||||
* Created on: Nov 12, 2021
|
||||
* Author: angoosh
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Page wite writes 8 bytes to whole page or memory row => bytes A7-A3 are the same
|
||||
* Word address 11111111 is reserved
|
||||
*/
|
||||
#ifndef INC_AT24CSW_H_
|
||||
#define INC_AT24CSW_H_
|
||||
|
||||
#include "stm32l0xx_hal.h"
|
||||
|
||||
#define PRODUCT_LAST_NUMBER 0
|
||||
|
||||
#define AT24CSW_ADDRESS 0b1010000 + PRODUCT_LAST_NUMBER
|
||||
#define AT24CSW_SEC_ADDRESS 0b1011000 + PRODUCT_LAST_NUMBER
|
||||
|
||||
|
||||
|
||||
|
||||
int AT24CSW_Read_Memory(uint8_t address, uint8_t size, uint8_t *data);
|
||||
int AT24CSW_Page_Write(uint8_t address, uint8_t *bytes);
|
||||
int AT24CSW_Byte_Write(uint8_t address, uint8_t byte);
|
||||
|
||||
#endif /* INC_AT24CSW_H_ */
|
21
MCP40D18.c
Normal file
21
MCP40D18.c
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* MCP40D18.c
|
||||
*
|
||||
* Created on: Sep 16, 2021
|
||||
* Author: angoosh
|
||||
*/
|
||||
#include "MCP40D18.h"
|
||||
#include "main.h"
|
||||
|
||||
void SetPotPosition(uint8_t pos);
|
||||
|
||||
extern I2C_HandleTypeDef MCP40D18_I2C_HANDLE;
|
||||
|
||||
|
||||
void SetPotPosition(uint8_t pos){
|
||||
if(pos < 128){
|
||||
uint8_t data[2] = {0,pos};
|
||||
HAL_I2C_Master_Transmit(&MCP40D18_I2C_HANDLE, (MCP_I2C_ADDRESS << 1), data, 2, 0xFFFF);
|
||||
}
|
||||
}
|
||||
|
23
MCP40D18.h
Normal file
23
MCP40D18.h
Normal file
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* MCP40D18.h
|
||||
*
|
||||
* Created on: Sep 16, 2021
|
||||
* Author: angoosh
|
||||
*/
|
||||
|
||||
#ifndef INC_MCP40D18_H_
|
||||
#define INC_MCP40D18_H_
|
||||
|
||||
#include "stm32l0xx_hal.h"
|
||||
|
||||
#define IS_ALT_ADDRESS
|
||||
#ifdef IS_ALT_ADDRESS
|
||||
#define MCP_I2C_ADDRESS 0x3E //0111110
|
||||
#else
|
||||
#define MCP_I2C_ADDRESS 0x2E //0101110
|
||||
#endif
|
||||
|
||||
|
||||
void SetPotPosition(uint8_t pos);
|
||||
|
||||
#endif /* INC_MCP40D18_H_ */
|
Loading…
x
Reference in New Issue
Block a user