2024-07-12
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
Tabula contentorum
1.1 Software ac hardware elit informationes
1.2 tabula Development notitia
2.1 Hardware interface circuit
2.3 Generate Keil project files
3.2 DS18B20 exactoris implementation
Renesas R7FA8D1BH (Cortex®-M85) moderatur DS18B20 et ADC ut munus jump consequi duarum paginarum
Articulus hic principaliter inducit applicationem comprehensivam causam designatam Renesas R7FA8D1BH (Cortex®-M85): applicans IO R7FA8D1BH ad efficiendum unum bus protocollum et munus ds18b20 impellendi perficiens propono in OLED in screen. Temperatura data etiam ad portum serialem per terminalem portum serialem mittitur.
Software ac hardware notitia | Versionem Information |
---|---|
Renesas MCU | R7FA8D1BH |
Keil | MDK ARM 5.38 |
FSP version | 5.3.0 |
Instrumentum debugging: N32G45XVL-STB | DAP-LINK |
Auctor evolutionis incendii Yaoyang uti tabulae Renesas RA8. Praecipuum imperium MCU huius tabulae est R7FA8D1BHECBD, et nucleus 7FA8D1BHECBD est ARM Contex-M85.
Pro R7FA8D1BHECBD chip, nucleus adhibitus est Cortex®-M85 Core, ST-LINK-V2 vel J-LINK-V9 non sustinet unctiones et debugging functiones.Post multos conatus auctor invenitN32G45XVL-STBDAP-LINK qui cum tabula venit extrahere potest et debug R7FA8D1BHECBD.
Pictura infra pictura corporis N32G45XVL-STB tabula evolutionis est:
Circuitus interfaciei DS18B20 in Yaoyang Development Board_Renesas RA8 designatus est, qui interfaciem P809 adhibet ut DQ imperium signo DS18B20.
Configurare P809 ut communis IO interfaciei, ac deinde dynamice configurare statum output vel output IO in codice.
Expleto modulo configurationis FSP, Project Generare potes. Aperi fasciculum documenti, cuius structura haec est:
Create in ds18b20.c lima coegi codice ad efficiendum
Auctor sincere et exsecutionem logicam DS18B20 in speciali iam in articulo suo praecedente evolvit, unde eam hic non introducam.
DS18B20 Applicationem Note_Waveformia ds18b20 lectionis data-CSDN Blog
Linea 14 Codicis: Defini nos munus morae gradum
Linea 15 codicis: Define ms gradus mora functionis
Linea 18 codicis: Definire IO ACUS DS18B20
Linea 21 codicis: Input portum configuratione
Linea 22 codicis: Output portum configuratione
Line 24 of code: Set IO low level
Line 25 of code: Pone IO altam gradum
Linea XLVII codicis: Lege statum IO in initus modus
Munus: ds18b20Init, deprehendere num DS18B20 est online?
Function: ds18b20BlockModeProcess. Legere valorem DS18B20
- /**
- * @brief reset DS18B20
- * @note if reset ds18b20 sucess, the return value is TRUE
- * @param None
- * @retval True or Flalse
- */
- static uint8_t ds18b20Init( void )
- {
- uint16_t tempCnt = 0;
- bsp_io_level_t status;
-
- // Set PIN mode output
- DS_Mode_Out_PP();
-
- // Master pin is high
- DQ_SET_HIGH;
- timeDelayUS(10);
-
- // Master pin is low
- DQ_SET_LOW;
- // wait for 600 us
- timeDelayUS(750);
-
- // Set PIN mode input
- DS_Mode_IN_PUT();
-
- while(1)
- {
- status = DQ_RAD_PIN();
- if( status == 0)
- {
- tempCnt = 0;
- return TRUE;
- }
- else
- {
- timeDelayUS(1);
- tempCnt++;
- if( tempCnt > 480 )
- return FALSE;
- }
- }
- }
-
-
- static uint8_t readBit( void )
- {
- uint8_t readCnt = 2;
- uint8_t bitVal = 1;
-
- DQ_SET_LOW;
- timeDelayUS(3);
- DQ_SET_HIGH;
-
- timeDelayUS(5); // 15 us
-
- while(readCnt-- )
- {
- //read DQ value
- if( DQ_RAD_PIN() == 0)
- {
- bitVal = 0;
- }
- timeDelayUS(2); // 15 us
- }
-
- timeDelayUS(30); // 15 us
-
- return bitVal;
- }
-
- static uint8_t ds18b20ReadByte( void )
- {
- uint8_t byteVal = 0;
-
- for ( uint8_t i = 0; i < 8; i++ )
- {
- byteVal >>= 1;
-
- uint8_t bitVal = readBit();
- if( bitVal > 0)
- {
- byteVal |= 0x80;
- }
- }
-
- return byteVal;
- }
-
-
- /**
- * @brief write one byte to DS18B20
- * @note
- * @param byte: the data that is sended to ds18b20
- * @retval None
- */
- void ds18b20WriteByte( uint8_t byte)
- {
- unsigned char k;
-
- // Set PIN mode output
- DS_Mode_Out_PP();
-
- for ( k = 0; k < 8; k++ )
- {
- if (byte & (1<<k))
- {
- DQ_SET_LOW;
- timeDelayUS(2);
-
- DQ_SET_HIGH;
- timeDelayUS(65);
- }
- else
- {
- DQ_SET_LOW;
- timeDelayUS(65);
-
- DQ_SET_HIGH;
- timeDelayUS(2);
- }
- }
- }
-
- uint8_t ds18b20BlockModeProcess( void )
- {
- uint16_t tempValue;
- uint8_t tempL, tempH;
-
- if (ds18b20Init() == FALSE)
- {
- return FALSE;
- }
-
- // wait for 600 us
- timeDelayUS(600);
-
- ds18b20WriteByte(0xcc);
- ds18b20WriteByte(0x44); // start convert temperature
-
- if (ds18b20Init() == FALSE)
- {
- return FALSE;
- }
- // wait for 600 us
- timeDelayUS(600);
-
- ds18b20WriteByte(0xcc);
- ds18b20WriteByte(0xbe); // read temperature data register
-
- tempL = ds18b20ReadByte();
- tempH = ds18b20ReadByte();
-
- if (tempH > 0x7f)
- {
- tempL = ~tempL;
- tempH = ~tempH+1;
- st_ds1b20val.sign = 1;
- }
-
- tempValue = (uint16_t)((tempH << 8) | tempL);
-
- st_ds1b20val.temperatureVal = (float)(tempValue * 0.0625);
-
- return TRUE;
- }
-
-
- // NO blocking mode operate ds18b20
- uint8_t ds18b20NoBlockingProcess( void )
- {
- uint16_t tempValue;
- static uint16_t waitCnt = 0;
- uint8_t tempL, tempH;
- static uint8_t runState = 0;
-
- switch( runState )
- {
- default:
- case INIT_DQ:
- if (ds18b20Init() == FALSE)
- {
- return FALSE;
- }
- runState = WAIT_READY;
- break;
-
- case WAIT_READY:
- timeDelayUS(2); // IDEL
- runState = SKIDROM_CMD;
- break;
-
- case SKIDROM_CMD:
- ds18b20WriteByte(0xcc);
- ds18b20WriteByte(0x44); // begin to convert temperature data
- waitCnt = 0;
- runState = WAIT_CONVERT;
- break;
-
- case WAIT_CONVERT:
- waitCnt++;
- if( waitCnt > WAIT_CNT_CONVERT)
- {
- waitCnt = 0;
- runState = RESET_CMD;
- }
- break;
-
- case RESET_CMD:
- if (ds18b20Init() == FALSE)
- {
- return FALSE;
- }
- runState = WAIT_DATA_READY;
- break;
-
- case WAIT_DATA_READY:
- timeDelayUS(2); // IDEL
- runState = READ_CMD;
- break;
-
- case READ_CMD:
- ds18b20WriteByte(0xcc);
- ds18b20WriteByte(0xbe); // read temperature data register
- runState = GET_VALUE;
- break;
-
- case GET_VALUE:
-
- tempL = ds18b20ReadByte();
- tempH = ds18b20ReadByte();
-
- if (tempH > 0x7f)
- {
- tempL = ~tempL;
- tempH = ~tempH+1;
- st_ds1b20val.sign = 1;
- }
-
- tempValue = (uint16_t)((tempH << 8) | tempL);
-
- st_ds1b20val.temperatureVal = (float)(tempValue * 0.0625);
- runState = INIT_DQ;
- return TRUE;
- }
-
- return FALSE;
- }
Linea 113 codicis: Lege valorem ds18b20
Linea 130 codicis: Da exitum notitiae ds18b20 .
Linea CXXXI codicis: Formatted ostentationem data
Linea 132 codicis: Propono notitia in OLED
Codicem compone et codicem ad tabulam depone. Proventus currentium sunt haec:
DS18B20 coegi codice
I) crea in ds18b20.c lima et scribe sequenti codice
- /*
- FILE NAME : ds18b20.c
- Description: user ds18b20 interface
- Author : [email protected]
- Date : 2024/06/03
- */
- #include "ds18b20.h"
- #include "hal_data.h"
-
- typedef enum{
- INPUT = 0,
- OUTPUT = 1,
- }IO_TYPE;
-
- typedef enum{
- FALSE = 0,
- TRUE = 1,
- }RETURN_RESULT;
-
- typedef enum{
- INIT_DQ = 0,
- WAIT_READY,
- SKIDROM_CMD,
-
- WAIT_CONVERT,
- RESET_CMD,
- READ_CMD,
-
- WAIT_DATA_READY,
- GET_VALUE,
- IDLE_NULL
- }RUN_STATE;
-
- ds18b20Struc st_ds1b20val;
-
-
- ds18b20Struc get_ds18b20_value( void )
- {
- return st_ds1b20val;
- }
-
- static bsp_io_level_t DQ_RAD_PIN(void)
- {
- bsp_io_level_t state;
-
- // READ io
- R_IOPORT_PinRead(&g_ioport_ctrl, DS_IO_PORT_PIN, &state);
-
- return state;
- }
-
- /**
- * @brief reset DS18B20
- * @note if reset ds18b20 sucess, the return value is TRUE
- * @param None
- * @retval True or Flalse
- */
- static uint8_t ds18b20Init( void )
- {
- uint16_t tempCnt = 0;
- bsp_io_level_t status;
-
- // Set PIN mode output
- DS_Mode_Out_PP();
-
- // Master pin is high
- DQ_SET_HIGH;
- timeDelayUS(10);
-
- // Master pin is low
- DQ_SET_LOW;
- // wait for 600 us
- timeDelayUS(750);
-
- // Set PIN mode input
- DS_Mode_IN_PUT();
-
- while(1)
- {
- status = DQ_RAD_PIN();
- if( status == 0)
- {
- tempCnt = 0;
- return TRUE;
- }
- else
- {
- timeDelayUS(1);
- tempCnt++;
- if( tempCnt > 480 )
- return FALSE;
- }
- }
- }
-
-
- static uint8_t readBit( void )
- {
- uint8_t readCnt = 2;
- uint8_t bitVal = 1;
-
- DQ_SET_LOW;
- timeDelayUS(3);
- DQ_SET_HIGH;
-
- timeDelayUS(5); // 15 us
-
- while(readCnt-- )
- {
- //read DQ value
- if( DQ_RAD_PIN() == 0)
- {
- bitVal = 0;
- }
- timeDelayUS(2); // 15 us
- }
-
- timeDelayUS(30); // 15 us
-
- return bitVal;
- }
-
- static uint8_t ds18b20ReadByte( void )
- {
- uint8_t byteVal = 0;
-
- for ( uint8_t i = 0; i < 8; i++ )
- {
- byteVal >>= 1;
-
- uint8_t bitVal = readBit();
- if( bitVal > 0)
- {
- byteVal |= 0x80;
- }
- }
-
- return byteVal;
- }
-
-
- /**
- * @brief write one byte to DS18B20
- * @note
- * @param byte: the data that is sended to ds18b20
- * @retval None
- */
- void ds18b20WriteByte( uint8_t byte)
- {
- unsigned char k;
-
- // Set PIN mode output
- DS_Mode_Out_PP();
-
- for ( k = 0; k < 8; k++ )
- {
- if (byte & (1<<k))
- {
- DQ_SET_LOW;
- timeDelayUS(2);
-
- DQ_SET_HIGH;
- timeDelayUS(65);
- }
- else
- {
- DQ_SET_LOW;
- timeDelayUS(65);
-
- DQ_SET_HIGH;
- timeDelayUS(2);
- }
- }
- }
-
- uint8_t ds18b20BlockModeProcess( void )
- {
- uint16_t tempValue;
- uint8_t tempL, tempH;
-
- if (ds18b20Init() == FALSE)
- {
- return FALSE;
- }
-
- // wait for 600 us
- timeDelayUS(600);
-
- ds18b20WriteByte(0xcc);
- ds18b20WriteByte(0x44); // start convert temperature
-
- if (ds18b20Init() == FALSE)
- {
- return FALSE;
- }
- // wait for 600 us
- timeDelayUS(600);
-
- ds18b20WriteByte(0xcc);
- ds18b20WriteByte(0xbe); // read temperature data register
-
- tempL = ds18b20ReadByte();
- tempH = ds18b20ReadByte();
-
- if (tempH > 0x7f)
- {
- tempL = ~tempL;
- tempH = ~tempH+1;
- st_ds1b20val.sign = 1;
- }
-
- tempValue = (uint16_t)((tempH << 8) | tempL);
-
- st_ds1b20val.temperatureVal = (float)(tempValue * 0.0625);
-
- return TRUE;
- }
-
-
- // NO blocking mode operate ds18b20
- uint8_t ds18b20NoBlockingProcess( void )
- {
- uint16_t tempValue;
- static uint16_t waitCnt = 0;
- uint8_t tempL, tempH;
- static uint8_t runState = 0;
-
- switch( runState )
- {
- default:
- case INIT_DQ:
- if (ds18b20Init() == FALSE)
- {
- return FALSE;
- }
- runState = WAIT_READY;
- break;
-
- case WAIT_READY:
- timeDelayUS(2); // IDEL
- runState = SKIDROM_CMD;
- break;
-
- case SKIDROM_CMD:
- ds18b20WriteByte(0xcc);
- ds18b20WriteByte(0x44); // begin to convert temperature data
- waitCnt = 0;
- runState = WAIT_CONVERT;
- break;
-
- case WAIT_CONVERT:
- waitCnt++;
- if( waitCnt > WAIT_CNT_CONVERT)
- {
- waitCnt = 0;
- runState = RESET_CMD;
- }
- break;
-
- case RESET_CMD:
- if (ds18b20Init() == FALSE)
- {
- return FALSE;
- }
- runState = WAIT_DATA_READY;
- break;
-
- case WAIT_DATA_READY:
- timeDelayUS(2); // IDEL
- runState = READ_CMD;
- break;
-
- case READ_CMD:
- ds18b20WriteByte(0xcc);
- ds18b20WriteByte(0xbe); // read temperature data register
- runState = GET_VALUE;
- break;
-
- case GET_VALUE:
-
- tempL = ds18b20ReadByte();
- tempH = ds18b20ReadByte();
-
- if (tempH > 0x7f)
- {
- tempL = ~tempL;
- tempH = ~tempH+1;
- st_ds1b20val.sign = 1;
- }
-
- tempValue = (uint16_t)((tempH << 8) | tempL);
-
- st_ds1b20val.temperatureVal = (float)(tempValue * 0.0625);
- runState = INIT_DQ;
- return TRUE;
- }
-
- return FALSE;
- }
-
-
-
- /* End of this file */
II) crea in ds18b20.h lima et scribe in codice sequenti
- /*
- FILE NAME : ds18b20.h
- Description: user ds18b20 interface
- Author : [email protected]
- Date : 2024/06/03
- */
- #ifndef DS18B20_H
- #define DS18B20_H
- #include "hal_data.h"
-
-
- #define WAIT_CNT_CONVERT 500
-
- #define timeDelayUS(us) R_BSP_SoftwareDelay(us, BSP_DELAY_UNITS_MICROSECONDS);
- #define DS_DELAY_MS(ms) R_BSP_SoftwareDelay(ms, BSP_DELAY_UNITS_MILLISECONDS);
-
-
- #define DS_IO_PORT_PIN BSP_IO_PORT_08_PIN_09
-
-
- #define DS_Mode_IN_PUT() R_IOPORT_PinCfg(&g_ioport_ctrl, DS_IO_PORT_PIN, IOPORT_CFG_PORT_DIRECTION_INPUT)
- #define DS_Mode_Out_PP() R_IOPORT_PinCfg(&g_ioport_ctrl, DS_IO_PORT_PIN, IOPORT_CFG_PORT_DIRECTION_OUTPUT)
-
- #define DQ_SET_LOW R_IOPORT_PinWrite(&g_ioport_ctrl, DS_IO_PORT_PIN, BSP_IO_LEVEL_LOW)
- #define DQ_SET_HIGH R_IOPORT_PinWrite(&g_ioport_ctrl, DS_IO_PORT_PIN, BSP_IO_LEVEL_HIGH)
-
-
- typedef struct{
- float temperatureVal;
- bool sign;
- }ds18b20Struc;
-
- uint8_t ds18b20BlockModeProcess( void );
- ds18b20Struc get_ds18b20_value( void );
-
-
- #endif /* DS18B20_H */
-
-