存档:eeprom读写单个字节成功
This commit is contained in:
parent
a38785c12f
commit
7d7f0777e4
|
@ -2,7 +2,7 @@
|
||||||
* @Author: wujunchao wujunchao@wuxismart.com
|
* @Author: wujunchao wujunchao@wuxismart.com
|
||||||
* @Date: 2024-12-27 11:50:56
|
* @Date: 2024-12-27 11:50:56
|
||||||
* @LastEditors: wujunchao wujunchao@wuxismart.com
|
* @LastEditors: wujunchao wujunchao@wuxismart.com
|
||||||
* @LastEditTime: 2025-03-18 16:55:05
|
* @LastEditTime: 2025-03-19 10:47:42
|
||||||
* @FilePath: \signal_generator\App\APP_WU\Src\apps_gather.c
|
* @FilePath: \signal_generator\App\APP_WU\Src\apps_gather.c
|
||||||
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
||||||
*/
|
*/
|
||||||
|
@ -801,7 +801,7 @@ void scr_init_run(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// uint8_t eep_tx = 72;
|
// uint8_t eep_tx = 0x72;
|
||||||
// uint8_t eep_rx = 0;
|
// uint8_t eep_rx = 0;
|
||||||
// uint8_t eep_addr[3];
|
// uint8_t eep_addr[3];
|
||||||
// uint8_t eep_test_flag = 0;
|
// uint8_t eep_test_flag = 0;
|
||||||
|
@ -828,28 +828,13 @@ void scr_main_run(void)
|
||||||
|
|
||||||
|
|
||||||
// EEPROM_CS_L;
|
// EEPROM_CS_L;
|
||||||
// delay_cnt(0xff);
|
// delay_cnt(10);
|
||||||
// eep_status = SPI_WriteReadByte(WRITE_DISABLE);
|
// eeprom_spi_writebyte(READ_STATUS);
|
||||||
// delay_cnt(0xff);
|
// eep_status = eeprom_spi_readbyte();
|
||||||
|
// delay_cnt(10);
|
||||||
// EEPROM_CS_H;
|
// EEPROM_CS_H;
|
||||||
|
|
||||||
// EEPROM_CS_L;
|
// delay_cnt(100);
|
||||||
// delay_cnt(0xff);
|
|
||||||
// eep_status = SPI_WriteReadByte(READ_STATUS);
|
|
||||||
// delay_cnt(0xff);
|
|
||||||
// EEPROM_CS_H;
|
|
||||||
|
|
||||||
// EEPROM_CS_L;
|
|
||||||
// delay_cnt(0xff);
|
|
||||||
// eep_status = SPI_WriteReadByte(WRITE_ENABLE);
|
|
||||||
// delay_cnt(0xff);
|
|
||||||
// EEPROM_CS_H;
|
|
||||||
|
|
||||||
// EEPROM_CS_L;
|
|
||||||
// delay_cnt(0xff);
|
|
||||||
// eep_status = SPI_WriteReadByte(READ_STATUS);
|
|
||||||
// delay_cnt(0xff);
|
|
||||||
// EEPROM_CS_H;
|
|
||||||
|
|
||||||
// if(eep_test_flag == 0)
|
// if(eep_test_flag == 0)
|
||||||
// {
|
// {
|
||||||
|
@ -1085,6 +1070,7 @@ void set_nixie_cube(uint8_t io_slc, uint8_t pos, int32_t num)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
//只负责数字部分,不管符号
|
||||||
case IO_OUTPUT:
|
case IO_OUTPUT:
|
||||||
{
|
{
|
||||||
switch (pos)
|
switch (pos)
|
||||||
|
@ -1201,7 +1187,7 @@ void set_nixie_cube(uint8_t io_slc, uint8_t pos, int32_t num)
|
||||||
|
|
||||||
if(num > 9999999)
|
if(num > 9999999)
|
||||||
{
|
{
|
||||||
num = 99999999;
|
num = 9999999;
|
||||||
}
|
}
|
||||||
else if(num < 0)
|
else if(num < 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* @Author: wujunchao wujunchao@wuxismart.com
|
* @Author: wujunchao wujunchao@wuxismart.com
|
||||||
* @Date: 2025-03-17 14:38:34
|
* @Date: 2025-03-17 14:38:34
|
||||||
* @LastEditors: wujunchao wujunchao@wuxismart.com
|
* @LastEditors: wujunchao wujunchao@wuxismart.com
|
||||||
* @LastEditTime: 2025-03-18 09:18:55
|
* @LastEditTime: 2025-03-19 10:44:31
|
||||||
* @FilePath: \signal_generator\App\APP_WU\Src\eeprom_spi.c
|
* @FilePath: \signal_generator\App\APP_WU\Src\eeprom_spi.c
|
||||||
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
||||||
*/
|
*/
|
||||||
|
@ -40,11 +40,11 @@ void eeprom_spi_writebyte(uint8_t wrt_data)
|
||||||
EEPROM_MOSI_L;
|
EEPROM_MOSI_L;
|
||||||
}
|
}
|
||||||
|
|
||||||
wu_delay_us(10); // 空等待
|
wu_delay_us(5); // 空等待
|
||||||
|
|
||||||
EEPROM_SCLK_H; //CPHA=0
|
EEPROM_SCLK_H; //CPHA=0
|
||||||
|
|
||||||
wu_delay_us(10); // 空等待
|
wu_delay_us(5); // 空等待
|
||||||
}
|
}
|
||||||
|
|
||||||
EEPROM_SCLK_L;
|
EEPROM_SCLK_L;
|
||||||
|
@ -63,10 +63,10 @@ uint8_t eeprom_spi_readbyte(void)
|
||||||
{
|
{
|
||||||
read_data = read_data << 1;
|
read_data = read_data << 1;
|
||||||
EEPROM_SCLK_L;
|
EEPROM_SCLK_L;
|
||||||
wu_delay_us(10); // 空等待
|
wu_delay_us(5); // 空等待
|
||||||
EEPROM_SCLK_H;
|
EEPROM_SCLK_H;
|
||||||
wu_delay_us(10); // 空等待
|
wu_delay_us(5); // 空等待
|
||||||
if(EEPROM_MISO == 1)
|
if(EEPROM_MISO)
|
||||||
{
|
{
|
||||||
read_data = read_data + 1;
|
read_data = read_data + 1;
|
||||||
}
|
}
|
||||||
|
@ -97,13 +97,13 @@ uint8_t SPI_WriteReadByte(uint8_t data)
|
||||||
|
|
||||||
data = (data << 1);
|
data = (data << 1);
|
||||||
EEPROM_SCLK_H;
|
EEPROM_SCLK_H;
|
||||||
delay_cnt(0xff);
|
wu_delay_us(5); // 空等待
|
||||||
if(EEPROM_MISO)
|
if(EEPROM_MISO)
|
||||||
{
|
{
|
||||||
data |= 0x01;
|
data |= 0x01;
|
||||||
}
|
}
|
||||||
EEPROM_SCLK_L;
|
EEPROM_SCLK_L;
|
||||||
delay_cnt(0xff);
|
wu_delay_us(5); // 空等待
|
||||||
}
|
}
|
||||||
|
|
||||||
//EEPROM_CS_H;
|
//EEPROM_CS_H;
|
||||||
|
@ -113,46 +113,70 @@ uint8_t SPI_WriteReadByte(uint8_t data)
|
||||||
|
|
||||||
void eeprom_writedata(uint8_t addr[3], uint8_t txd)
|
void eeprom_writedata(uint8_t addr[3], uint8_t txd)
|
||||||
{
|
{
|
||||||
|
uint8_t write_en_flag = 0;
|
||||||
|
uint8_t ee_status = 0;
|
||||||
|
|
||||||
EEPROM_CS_L;
|
EEPROM_CS_L;
|
||||||
delay_cnt(0xff);
|
delay_cnt(10);
|
||||||
eeprom_spi_writebyte(WRITE_ENABLE);
|
eeprom_spi_writebyte(WRITE_ENABLE);
|
||||||
delay_cnt(0xff);
|
delay_cnt(10);
|
||||||
EEPROM_CS_H;
|
EEPROM_CS_H;
|
||||||
|
|
||||||
EEPROM_CS_L;
|
EEPROM_CS_L;
|
||||||
delay_cnt(0xff);
|
delay_cnt(10);
|
||||||
|
eeprom_spi_writebyte(READ_STATUS);
|
||||||
eeprom_spi_writebyte(WRITE_MEMORY);
|
ee_status = eeprom_spi_readbyte();
|
||||||
eeprom_spi_writebyte(addr[0]);
|
delay_cnt(10);
|
||||||
eeprom_spi_writebyte(addr[1]);
|
|
||||||
eeprom_spi_writebyte(addr[2]);
|
|
||||||
eeprom_spi_writebyte(txd);
|
|
||||||
|
|
||||||
delay_cnt(0xff);
|
|
||||||
EEPROM_CS_H;
|
EEPROM_CS_H;
|
||||||
|
|
||||||
|
write_en_flag = ee_status & 0x02;
|
||||||
|
if(write_en_flag)
|
||||||
|
{
|
||||||
|
EEPROM_CS_L;
|
||||||
|
delay_cnt(10);
|
||||||
|
eeprom_spi_writebyte(WRITE_MEMORY);
|
||||||
|
eeprom_spi_writebyte(addr[0]);
|
||||||
|
eeprom_spi_writebyte(addr[1]);
|
||||||
|
eeprom_spi_writebyte(addr[2]);
|
||||||
|
eeprom_spi_writebyte(txd);
|
||||||
|
delay_cnt(10);
|
||||||
|
EEPROM_CS_H;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t eeprom_readdata(uint8_t addr[3])
|
uint8_t eeprom_readdata(uint8_t addr[3])
|
||||||
{
|
{
|
||||||
uint8_t rxd = 0;
|
uint8_t rxd = 0;
|
||||||
|
uint8_t write_en_flag = 0;
|
||||||
|
uint8_t ee_status = 0;
|
||||||
|
|
||||||
EEPROM_CS_L;
|
EEPROM_CS_L;
|
||||||
delay_cnt(0xff);
|
delay_cnt(10);
|
||||||
eeprom_spi_writebyte(WRITE_ENABLE);
|
eeprom_spi_writebyte(WRITE_ENABLE);
|
||||||
delay_cnt(0xff);
|
delay_cnt(10);
|
||||||
EEPROM_CS_H;
|
EEPROM_CS_H;
|
||||||
|
|
||||||
EEPROM_CS_L;
|
EEPROM_CS_L;
|
||||||
delay_cnt(0xff);
|
delay_cnt(10);
|
||||||
|
eeprom_spi_writebyte(READ_STATUS);
|
||||||
eeprom_spi_writebyte(READ_MEMORY);
|
ee_status = eeprom_spi_readbyte();
|
||||||
eeprom_spi_writebyte(addr[0]);
|
delay_cnt(10);
|
||||||
eeprom_spi_writebyte(addr[1]);
|
|
||||||
eeprom_spi_writebyte(addr[2]);
|
|
||||||
rxd = eeprom_spi_readbyte();
|
|
||||||
|
|
||||||
delay_cnt(0xff);
|
|
||||||
EEPROM_CS_H;
|
EEPROM_CS_H;
|
||||||
|
|
||||||
|
write_en_flag = ee_status & 0x02;
|
||||||
|
if(write_en_flag)
|
||||||
|
{
|
||||||
|
EEPROM_CS_L;
|
||||||
|
delay_cnt(10);
|
||||||
|
eeprom_spi_writebyte(READ_MEMORY);
|
||||||
|
eeprom_spi_writebyte(addr[0]);
|
||||||
|
eeprom_spi_writebyte(addr[1]);
|
||||||
|
eeprom_spi_writebyte(addr[2]);
|
||||||
|
rxd = eeprom_spi_readbyte();
|
||||||
|
delay_cnt(10);
|
||||||
|
EEPROM_CS_H;
|
||||||
|
}
|
||||||
|
|
||||||
return rxd;
|
return rxd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue