bsp_i2c ok
This commit is contained in:
parent
a4e58354cd
commit
77d80fe273
|
@ -90,7 +90,7 @@
|
||||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/Ld/Link.ld}""/>
|
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/Ld/Link.ld}""/>
|
||||||
</option>
|
</option>
|
||||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.nostart.913830613" name="Do not use standard start files (-nostartfiles)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.nostart" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.nostart.913830613" name="Do not use standard start files (-nostartfiles)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.nostart" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.usenewlibnano.239404511" name="Use newlib-nano (--specs=nano.specs)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.usenewlibnano" useByScannerDiscovery="false" value="false" valueType="boolean"/>
|
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.usenewlibnano.239404511" name="Use newlib-nano (--specs=nano.specs)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.usenewlibnano" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.usenewlibnosys.351964161" name="Do not use syscalls (--specs=nosys.specs)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.usenewlibnosys" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.usenewlibnosys.351964161" name="Do not use syscalls (--specs=nosys.specs)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.usenewlibnosys" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="true" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.otherobjs.16994550" name="Other objects" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.otherobjs" useByScannerDiscovery="false" valueType="userObjs"/>
|
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="true" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.otherobjs.16994550" name="Other objects" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.otherobjs" useByScannerDiscovery="false" valueType="userObjs"/>
|
||||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.strip.1780837525" name="Omit all symbol information (-s)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.strip" useByScannerDiscovery="false" value="false" valueType="boolean"/>
|
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.strip.1780837525" name="Omit all symbol information (-s)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.strip" useByScannerDiscovery="false" value="false" valueType="boolean"/>
|
||||||
|
@ -103,9 +103,9 @@
|
||||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.flags.1577723329" name="Linker flags (-Xlinker [option])" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.flags" useByScannerDiscovery="false" valueType="stringList">
|
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.flags.1577723329" name="Linker flags (-Xlinker [option])" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.flags" useByScannerDiscovery="false" valueType="stringList">
|
||||||
<listOptionValue builtIn="false" value="--print-memory-usage"/>
|
<listOptionValue builtIn="false" value="--print-memory-usage"/>
|
||||||
</option>
|
</option>
|
||||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.printfloat.1191876922" name="Use wchprintfloat(-lprintfloat)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.printfloat" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.printfloat.1191876922" name="Use wchprintfloat(-lprintfloat)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.printfloat" useByScannerDiscovery="false" value="false" valueType="boolean"/>
|
||||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.other.1168669005" name="Other linker flags" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.other" useByScannerDiscovery="false" value="" valueType="string"/>
|
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.other.1168669005" name="Other linker flags" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.other" useByScannerDiscovery="false" value="" valueType="string"/>
|
||||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.useprintffloat.978715450" name="Use float with nano printf (-u _printf_float)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.useprintffloat" useByScannerDiscovery="false" value="false" valueType="boolean"/>
|
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.useprintffloat.978715450" name="Use float with nano printf (-u _printf_float)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.useprintffloat" useByScannerDiscovery="false" value="true" valueType="boolean"/>
|
||||||
<inputType id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.linker.input.1859223768" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.linker.input">
|
<inputType id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.linker.input.1859223768" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.linker.input">
|
||||||
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
|
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
|
||||||
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
|
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
|
||||||
|
@ -173,4 +173,5 @@
|
||||||
</storageModule>
|
</storageModule>
|
||||||
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
|
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
|
||||||
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
|
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
|
||||||
|
<storageModule moduleId="refreshScope"/>
|
||||||
</cproject>
|
</cproject>
|
||||||
|
|
6
.project
6
.project
|
@ -1,7 +1,7 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
<projectDescription>
|
<projectDescription>
|
||||||
<name>BLE_TYQ_CH592F</name>
|
<name>BLE_TYQ_CH592F</name>
|
||||||
<comment></comment>
|
<comment/>
|
||||||
<projects>
|
<projects>
|
||||||
</projects>
|
</projects>
|
||||||
<buildSpec>
|
<buildSpec>
|
||||||
|
@ -26,7 +26,7 @@
|
||||||
<filteredResources>
|
<filteredResources>
|
||||||
<filter>
|
<filter>
|
||||||
<id>1602468250279</id>
|
<id>1602468250279</id>
|
||||||
<name></name>
|
<name/>
|
||||||
<type>22</type>
|
<type>22</type>
|
||||||
<matcher>
|
<matcher>
|
||||||
<id>org.eclipse.ui.ide.multiFilter</id>
|
<id>org.eclipse.ui.ide.multiFilter</id>
|
||||||
|
|
|
@ -165,6 +165,8 @@ int main(void)
|
||||||
|
|
||||||
BSP_KEY_Init();
|
BSP_KEY_Init();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
BSP_ADC_Init();
|
BSP_ADC_Init();
|
||||||
CH59x_BLEInit();
|
CH59x_BLEInit();
|
||||||
|
|
||||||
|
@ -177,11 +179,12 @@ int main(void)
|
||||||
GAPRole_PeripheralInit();
|
GAPRole_PeripheralInit();
|
||||||
Peripheral_Init();
|
Peripheral_Init();
|
||||||
|
|
||||||
DelayMs(100);
|
|
||||||
GXHTC3C_Init();
|
|
||||||
|
|
||||||
BSP_FLASH_Init();
|
BSP_FLASH_Init();
|
||||||
|
|
||||||
|
DelayMs(100);
|
||||||
|
GXHTC3C_Init();
|
||||||
|
|
||||||
Main_Circulation();
|
Main_Circulation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,8 @@ static struct i2c_slave_cb *slave_cb = NULL;
|
||||||
#define MASTER_ADDR 0x42
|
#define MASTER_ADDR 0x42
|
||||||
|
|
||||||
uint8_t i2c_tx_data[2];
|
uint8_t i2c_tx_data[2];
|
||||||
uint8_t i2c_rx_data[6];
|
// __attribute__((aligned(4)))
|
||||||
|
uint8_t i2c_rx_data[8];
|
||||||
|
|
||||||
void BSP_I2C_Init(uint8_t address)
|
void BSP_I2C_Init(uint8_t address)
|
||||||
{
|
{
|
||||||
|
@ -95,7 +96,7 @@ int I2C_Write(uint8_t addr_7bit, const uint8_t *data, uint8_t length,
|
||||||
i2c_master_buffer_index = 0;
|
i2c_master_buffer_index = 0;
|
||||||
i2c_master_buffer_length = length;
|
i2c_master_buffer_length = length;
|
||||||
|
|
||||||
memcpy(i2c_master_buffer, data, length);
|
tmos_memcpy(i2c_master_buffer, data, length);
|
||||||
|
|
||||||
i2c_slave_addr_rw = I2C_WRITE;
|
i2c_slave_addr_rw = I2C_WRITE;
|
||||||
i2c_slave_addr_rw |= addr_7bit << 1;
|
i2c_slave_addr_rw |= addr_7bit << 1;
|
||||||
|
@ -201,7 +202,7 @@ int I2C_Read(uint8_t addr_7bit, uint8_t *data, uint8_t length,
|
||||||
length = i2c_master_buffer_index;
|
length = i2c_master_buffer_index;
|
||||||
|
|
||||||
// copy i2c buffer to data
|
// copy i2c buffer to data
|
||||||
memcpy(data, i2c_master_buffer, length);
|
tmos_memcpy(data, i2c_master_buffer, length);
|
||||||
|
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
@ -279,7 +280,7 @@ void GXHTC3C_SendCmd(uint16_t cmd)
|
||||||
i2c_tx_data[0] = HI_UINT16(cmd);
|
i2c_tx_data[0] = HI_UINT16(cmd);
|
||||||
i2c_tx_data[1] = LO_UINT16(cmd);
|
i2c_tx_data[1] = LO_UINT16(cmd);
|
||||||
ret = I2C_Write(GXHTC3C_ADDR, (const uint8_t *)&i2c_tx_data, 2, true, true);
|
ret = I2C_Write(GXHTC3C_ADDR, (const uint8_t *)&i2c_tx_data, 2, true, true);
|
||||||
logDebug("GXHTC3C_SendCmd %s", ret ? "failed" : "success");
|
// logDebug("GXHTC3C_SendCmd %s", ret ? "failed" : "success");
|
||||||
}
|
}
|
||||||
|
|
||||||
void GXHTC3C_Sleep(void)
|
void GXHTC3C_Sleep(void)
|
||||||
|
@ -361,8 +362,8 @@ uint8_t GXHTC3C_GetTempHumi(float *humi, float *temp)
|
||||||
|
|
||||||
if ((crc_humi == i2c_rx_data[2]) && (crc_temp == i2c_rx_data[5]))
|
if ((crc_humi == i2c_rx_data[2]) && (crc_temp == i2c_rx_data[5]))
|
||||||
{
|
{
|
||||||
logDebug("crc ok");
|
// logDebug("crc ok");
|
||||||
logHexDumpAll(i2c_rx_data, 6);
|
// logHexDumpAll(i2c_rx_data, 6);
|
||||||
|
|
||||||
*humi = (100.0 * raw_humi) / 65536.0; // 湿度真实值
|
*humi = (100.0 * raw_humi) / 65536.0; // 湿度真实值
|
||||||
*temp = (175.0 * raw_temp) / 65536.0 - 45.0; // 温度真实值
|
*temp = (175.0 * raw_temp) / 65536.0 - 45.0; // 温度真实值
|
||||||
|
@ -375,6 +376,7 @@ uint8_t GXHTC3C_GetTempHumi(float *humi, float *temp)
|
||||||
logError("crc error");
|
logError("crc error");
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
// logDebug("0 success");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -391,6 +393,7 @@ void GXHTC3C_Read(void)
|
||||||
ret = GXHTC3C_GetTempHumi(&humi, &temp);
|
ret = GXHTC3C_GetTempHumi(&humi, &temp);
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
{
|
{
|
||||||
|
// logDebug("ret=0");
|
||||||
logDebug("humi %.2f %, temp %.2f C", humi, temp);
|
logDebug("humi %.2f %, temp %.2f C", humi, temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -415,7 +418,7 @@ void GXHTC3C_Init(void)
|
||||||
ret = GXHTC3C_GetTempHumi(&humi, &temp);
|
ret = GXHTC3C_GetTempHumi(&humi, &temp);
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
{
|
{
|
||||||
logDebug("humi %.2f %, temp %.2f C", humi, temp);
|
// logDebug("humi %.2f %, temp %.2f C", humi, temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
GXHTC3C_Sleep();
|
GXHTC3C_Sleep();
|
||||||
|
|
|
@ -22,6 +22,7 @@ unsigned int BSP_Uart1_Send_Data(const void *buf, unsigned int len)
|
||||||
unsigned int ret;
|
unsigned int ret;
|
||||||
|
|
||||||
ret = lwrb_write(&Uart1Tx, buf, len);
|
ret = lwrb_write(&Uart1Tx, buf, len);
|
||||||
|
BSP_UART1_TxLoop();
|
||||||
// UART1_INTCfg(ENABLE, RB_IER_THR_EMPTY);
|
// UART1_INTCfg(ENABLE, RB_IER_THR_EMPTY);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue