薄膜10s是什么意思,硅上量子点激光器报告最新进展总结(一) -爱游戏平台

苗坤旺离型膜

馃摎聽鍓嶈█

馃搼鍗氬涓婚〉锛欯涓樻瘮鐗规儵缃氶檰

馃挅娆㈣繋鍏虫敞锛氱偣璧炴敹钘忊瓙鐣欒█鉁?馃挰绯诲垪涓撴爮锛歸eb鍓嶇銆佸祵鍏ュ紡銆佺瑪璁颁笓鏍?馃幃 鍔犲叆绀惧尯锛?涓樻瘮鐗规儵缃氶檰 馃浜虹敓鏍艰█锛氶€夊鏂瑰悜锛屾瘡璧颁竴姝ラ兘鏄繘姝ワ紒 鉁掞笍娆㈣繋澶т浆鎸囨锛屼竴璧峰涔狅紒涓€璧峰姞娌癸紒

馃憦 甯屾湜澶у鑳藉皬鎵嬩竴鍔紝甯繖鐐逛釜璧烇紒

馃榿璧勬簮閭锛?237814512@qq.com聽

鐩綍

馃摎聽鍓嶈█

宓屽叆寮忕畝浠?/p>

聽 宓屽叆寮忕郴缁熷畾涔?/p>

宓屽叆寮忓彂灞曡繃绋嬄?/p>

聽宓屽叆寮忓井澶勭悊鍣紙鍗曟澘璁$畻鏈猴級

stm32f40x鏈€灏忕郴缁?/p>

1銆佹惌寤哄紑鍙戠幆澧?/p>

1.寮€鍙戣鏄?/p>

1.1杞欢瀹夎

2. 杞欢娉ㄥ唽聽

3.瀹夎鐩稿簲鐨勮姱鐗囧寘聽

4.瀹夎涓嬭浇鍣ㄩ┍鍔?/p>

2銆丟pio瀹為獙聽

2.1gpio姒傝堪

2.2 gpio鐨勪富瑕佺壒寰?/p>

2.3 鍙橀噺鍜屽瘎瀛樺櫒

2.4 gpio瀹為獙锛堟寜閿偣浜甃ed鐏級

3銆佷腑鏂疄楠?/p>

3.1涓柇绠€浠?/p>

3.1.1涓柇姒傚康

3.1.2 涓柇鎰忎箟

3.2 stm32鐨勪腑鏂?/p>

3.2.1 stm32涓柇鐨勭壒鎬?/p>

3.2.2 nvic鎺у埗鍣ㄧ殑浼樺厛绾ц〃绀?/p>

3.3 涓柇鍚戦噺琛?/p>

3.4 stm32涓柇缂栫▼

3.4.1 nvic鍒嗙粍璁剧疆聽

3.4.2 nvic浼樺厛绾х紪鐮?/p>

3.4.3 nvic浼樺厛绾ч厤缃?/p>

3.4.4 nvic涓柇浣胯兘

3.4.5 鍒濆鍖朜vic鎺у埗鍣ㄧ殑姝ラ

3.4.6 涓柇鏈嶅姟鍑芥暟缂栧啓

4.uart鍜孶sart聽

4.1 uart绠€浠?/p>

4.2 usart

4.3 uart鐗规€?/p>

聽4.4 涓插彛濡備綍宸ヤ綔

4.5 涓嶶art鐩稿叧鐨勫瘎瀛樺櫒

聽 聽4.5.1 鐘舵€佸瘎瀛樺櫒锛圲sart_sr锛壜?/p>

4.5.2 鏁版嵁瀵勫瓨鍣紙usart_dr锛?/p>

4.5.3 娉㈢壒鐜囧瘎瀛樺櫒锛圲sart_brr锛壜?/p>

4.5.4 鎺у埗瀵勫瓨鍣紙usart_cr1锛?/p>

4.5.5 鎺у埗瀵勫瓨鍣紙usart_cr2锛?/p>

4.5.6 鎺у埗瀵勫瓨鍣?锛圲sart_cr3锛?/p>

4.5.7 淇濇姢鏃堕棿鍜岄鍒嗛usart_gtpr锛?/p>

4.5.8 绋嬪簭閰嶇疆姝ラ

4.5.9 瀹炰緥浠g爜

5.绯荤粺婊寸瓟瀹氭椂鍣?/p>

5.1 绯荤粺婊寸瓟瀹氭椂鍣ㄦ杩?/p>

5.2 绯荤粺婊寸瓟瀹氭椂鍣ㄧ殑浣滅敤

5.3 绯荤粺婊寸瓟瀹氭椂鍣ㄥ瘎瀛樺櫒

5.5 浠g爜瀹炰緥

6.瀹氭椂鍣?/p>

6.1 閫氱敤瀹氭椂鍣?/p>

6.2 stm32f4绯诲垪閫氱敤瀹氭椂鍣ㄧ壒鐐?/p>

6.3 涓庡熀鏈畾鏃跺櫒鐩稿叧鐨勫瘎瀛樺櫒

6.3.1 tim6鍜孴im7鎺у埗瀵勫瓨鍣?锛圱imx_cr1锛?/p>

6.3.2 tim6鍜孴im7鎺у埗瀵勫瓨鍣?锛圱imx_cr2锛?/p>

6.3.3聽tim6 鍜?tim7 dma/涓柇浣胯兘瀵勫瓨鍣?(timx_dier)

6.3.4 tim6鍜孴im7鐘舵€佸瘎瀛樺櫒锛圱imx_sr锛?/p>

6.3.5聽tim6鍜孴im7浜嬩欢鐢熶骇瀵勫瓨鍣紙timx_egr锛?/p>

6.3.6聽tim6鍜孴im7璁℃暟鍣紙timx_cnt锛?/p>

6.3.7 tim6鍜孴im7棰勫垎棰戝櫒锛圱imx_psc锛?/p>

6.3.8聽tim6鍜孴im7鑷姩閲嶈浇瀵勫瓨鍣紙timx_arr锛?/p>

6.4 瀹炰緥浠g爜

7.rtc瀹炴椂鏃堕挓

7.1 绠€浠?/p>

7.2 stm32f4绯诲垪rtc鐗圭偣

7.3 rtc 鍒濆鍖栧拰閰嶇疆

7.3.1 瀵勫瓨鍣ㄨ闂?/p>

7.3.2聽瀵勫瓨鍣ㄥ啓淇濇姢

7.3.3聽鏃ュ巻鍒濆鍖栧拰閰嶇疆

7.3.4 澶忎护鏃?/p>

7.4 rtc 鐩稿叧瀵勫瓨鍣?/p>

7.4.1 rtc 鏃堕棿瀵勫瓨鍣紙rtc_tr锛?/p>

7.4.2 rtc鏃ユ湡瀵勫瓨鍣紙rtc_dr锛?/p>

7.4.3 rtc鎺у埗瀵勫瓨鍣?/p>

7.4.4 rtc鍒濆鍖栧拰鐘舵€佸瘎瀛樺櫒锛圧tc_isr锛?/p>

7.4.5聽 rtc棰勫垎棰戝瘎瀛樺櫒锛圱rc_prer锛?/p>

7.4.6 rtc鍞ら啋瀹氭椂鍣ㄥ瘎瀛樺櫒锛圧tc_wutr锛?/p>

7.4.7 rtc鏍″噯瀵勫瓨鍣紙rtc_calibr锛?/p>

7.4.8 rtc闂归挓a瀵勫瓨鍣紙rtc_alrmar锛?/p>

7.4.9 rtc闂归挓b瀵勫瓨鍣紙rtc_alrmbr锛?/p>

7.4.10 rtc鍐欎繚鎶ゅ瘎瀛樺櫒锛圧tc_wpr锛?/p>

7.5 瀹炰緥浠g爜锛堝垵濮嬪寲鏃堕棿鍜屾棩鏈燂級

7.6 浠g爜瀹炵幇锛圧tc澶囦唤鍖?-澶嶄綅涓嶄慨鏀规椂闂达級

7.7 浠g爜瀹炵幇锛圠cd鏄剧ず 鍔ㄦ€佷慨鏀筊tc鏃堕棿鏃ユ湡锛?/p>

8 .鐪嬮棬鐙?/p>

8.1 鐪嬮棬鐙楃畝浠?/p>

8.2 鐪嬮棬鐙楃殑浣滅敤

8.3 鐪嬮棬鐙楃殑閫夋嫨聽 聽聽鈥嬬紪杈懧?/p>

8.4 鐙珛鐪嬮棬鐙?/p>

8.4.1 鏃堕挓

聽8.4.2聽ls鏃堕挓

8.4.3 鐗规€?/p>

8.4.4 棰勫垎棰?/p>

8.5 鐙珛鐪嬮棬鐙楀垵濮嬪寲聽

8.6 绐楀彛鐪嬮棬鐙?/p>

8.6.1 鐗圭偣

8.6.2 鍘熺悊聽

8.6.3聽 绐楀彛鐪嬮棬鐙楀垵濮嬪寲

8.6.4 婧愮爜绋嬪簭聽

9. rs485

9.1 姒傚康

9.2 鐗╃悊锛堢‖浠讹級鎺ュ彛鏍囧噯

9.2.1 ttl鐢靛钩

9.2.2 rs232

9.2.3 rs422聽

9.2.4 rs485

9.3 涓€涓讳竴浠庨€氫俊

9.3.1 涓绘満鎺ョ嚎

聽9.3.2 涓涙満鎺ョ嚎

9.3.3 涓讳粠鏈烘帴绾垮師鐞喡?/p>

9.4 涓绘満绋嬪簭聽

9.5 浠庢満绋嬪簭

9.6 涓€涓诲浠?鑷畾涔夊崗璁?/p>

9.6.1 鎼缓鑷畾涔夊崗璁?/p>

9.6.2 甯歌鐨勫崗璁鍒?/p>

聽9.6.3聽rs485鑷畾涔夊崗璁?1涓诲浠庨€氫俊-鎸夐敭鎺у埗-鍗曟鏁版嵁閫氫俊绋嬪簭

10銆丳wm

10.1 瀹氫箟

10.2 涓昏鍙傛暟

10.2.1 pwm鍗犵┖姣?/p>

10.2.2 pwm鐨勯鐜嚶?/p>

10.3 pwm浜х敓鐨勬柟寮?/p>

10.3.1 鏅€欼o鍙d笌pwm鍙?/p>

聽10.3.2聽鏅€欼o鍙d骇鐢烶wm

10.3.3聽pwm鍙d骇鐢烶wm

10.4 pwm绋嬪簭

11銆乄25q16/64

11.1 绠€浠?/p>

11.1.1 w25q64鑺墖浠嬬粛

11.2 寮曡剼

11.2.1聽spi鐗囬€夛紙/cs锛夊紩鑴氱敤浜庝娇鑳藉拰绂佹鑺墖鎿嶄綔聽

11.2.2聽涓茶鏁版嵁杈撳叆銆佽緭鍑哄拰 ios锛圖i銆丏o 鍜?io0銆両o1銆両o2銆両o3锛?/p>

11.2.3 鍐欎繚鎶わ紙/wp锛?/p>

11.2.4 涓茶鏃堕挓锛圕lk锛?/p>

11.3 w25q64鏍囧噯鐨凷pi鎿嶄綔

11.4 w25q瀹炰緥浠g爜

12.瑙︽懜灞?/p>

聽12.1瀹炵墿鍥?/p>

12.2 瑙︽懜灞忕绫诲垎绫?/p>

聽 聽12.2.1 鐢甸樆寮忓睆骞?/p>

12.2.2 鐢垫劅寮忚е鎽稿睆

聽12.2.3 绾㈠绾垮紡

12.2.4 琛ㄩ潰澹版尝寮?/p>

12.3 xpt2046閲囬泦瑙︽懜ad鑺墖

聽 聽12.3.1 瑙︽懜灞忔帴鍙h繛鎺ュ師鐞?/p>

12.3.2 xpt2046鐗规€?/p>

12.3.3 xpt2046缁撴瀯鍘熺悊

聽12.3.4 xpt2046寮曡剼

聽12.3.5 浣跨敤鍒扮殑寮曡剼

灏忕粨

12.4 xpt2046鎺у埗璇存槑

12.4.1 鍗曠杩樻槸宸垎妯″紡

12.4.2 绗斾腑鏂緭鍑?/p>

12.4.3 鎺у埗瀛楄妭

12.5 浠g爜瀹炰緥

聽鎵弿瑙︽懜灞?/p>

璇诲彇x/y杞碅d鍊硷紝骞舵护娉㈠鐞?/p>

璇诲彇杞碅d鍊?/p>

瑙︽懜灞忔牎鍑嗗嚱鏁?/p>

宓屽叆寮忕畝浠?/p>

聽 宓屽叆寮忕郴缁熷畾涔?/p>

宓屽叆寮忕郴缁熺殑瀹氫箟鏈夊緢澶氱殑璇存硶锛屼絾鏄病鏈変竴涓畾涔夋槸鍏ㄩ潰鐨勶紝涓嬮潰缁欏埌鐨勪袱绉嶆柟娉曟垜瑙夊緱搴旇绠楁槸姣旇緝鍚堢悊鐨勩€?/p>

浠庢妧鏈殑瑙掑害锛氬祵鍏ュ紡鏄互搴旂敤涓轰腑蹇冿紝浠ヨ绠楁満涓哄熀纭€鐨勩€佽蒋纭欢鍙鍓€侀€傚簲搴旂敤绯荤粺瀵瑰姛鑳姐€佸彲闈犳€с€佹垚鏈€佷綋绉€佸姛鑰椾弗鏍艰姹傜殑涓撶敤璁$畻鏈虹郴缁燂紱浠庣郴缁熺殑瑙掑害锛氬祵鍏ュ紡绯荤粺鏄璁″畬鎴愬鏉傚姛鑳界殑纭欢鍜岃蒋浠讹紝骞跺皢瀹冧滑绱у瘑鍦ㄤ竴璧风殑璁$畻鏈虹郴缁熴€?/p>

宓屽叆寮忕郴缁熺殑瀹炰緥--鎴戜滑鍙互閫氳繃姹借溅鎺у埗绯荤粺鏉ョ湅锛氬涓嬪浘

宓屽叆寮忓彂灞曡繃绋嬄?/p>

聽宓屽叆寮忓井澶勭悊鍣紙鍗曟澘璁$畻鏈猴級

聽 聽宓屽叆寮忓井澶勭悊鍣ㄧ殑鍩虹鏄€氱敤璁$畻鏈轰腑鐨凜pu锛屽湪搴旂敤褰撲腑锛屽皢寰鐞嗗櫒瑁呴厤鍦ㄤ笓闂ㄨ璁$殑鐢佃矾鏉夸笂闈紝鍙敤淇濈暀涓嬫垜浠拰宓屽叆寮忓簲鐢ㄦ湁鍏崇殑姣嶇増鐨勫姛鑳斤紝杩欐牱鍙互澶у箙搴︾殑鍑忓皬绯荤粺鐨勪綋绉拰鐩稿簲鐨勫姛鑰椼€備负浜嗘弧瓒冲祵鍏ュ紡搴旂敤鐨勭壒娈婅姹傦紝鎴戜滑宓屽叆寮忓井澶勭悊鍣ㄨ櫧鐒跺湪鍔熻兘涓婂拰鏍囧噯鐨勫井澶勭悊鍣ㄦ槸涓€鏍风殑锛屼絾鏄湪宸ヤ綔娓╁害銆佹姉鐢电娉㈢瓑绛夋柟闈竴鑸兘鍋氬埌浜嗗拰宸ヤ笟鎺у埗璁$畻鏈虹浉姣旇緝宓屽叆寮忓井澶勭悊鍣ㄤ綋绉皬銆侀噸閲忚交銆佹垚鏈綆銆佸彲闈犳€ч珮绛変紭鐐癸紝宓屽叆寮忓井澶勭悊鍣ㄤ互鍙婂瓨鍌ㄥ櫒銆佹€荤嚎銆佸璁剧瓑瀹夎鍦ㄤ竴鍧楃數璺澘涓婇潰鎴戜滑鎴愪负鍗曟澘璁$畻鏈?-鍗曠墖鏈猴紱浣嗘槸鍦ㄧ數璺澘涓婇潰蹇呴』鍖呭惈rom銆丷am銆佹€荤嚎鎺ュ彛銆佸璁炬帴鍙g瓑鏈熼棿锛涗粠鑰岄檷浣庣郴缁熺殑鍙潬鎬с€佹妧鏈繚瀵嗘€т篃姣旇緝宸紝鎵€浠ョ幇鍦ㄧ敤鐨勯兘姣旇緝灏戜簡銆?/p>

聽 聽宓屽叆寮忓鐞嗗櫒鐩墠涓昏鏈堿m186/88銆?86ex銆丼c-400銆丄rm绯诲垪绛夌瓑锛涘祵鍏ュ紡寰鐞嗗櫒鍙堝彲鍒嗕负cisc聽鍜孯isc涓ょ被銆傚ぇ瀹剁啛鎮夌殑澶у鏁板彴寮廝c閮芥槸浣跨敤cisc寰鐞嗗櫒锛屽intel鐨剎86銆俁isc缁撴瀯浣撶郴鏈変袱澶т富娴?silicon聽graphics鍏徃锛堢璋峰浘褰㈠叕鍙革級鐨凪ips鎶€鏈?arm鍏徃鐨凙dvanced聽risc聽machines鎶€鏈€傛澶栵紝hitachi锛堟棩绔嬪叕鍙革級涔熸湁鑷繁鐨勪竴濂桼isc鎶€鏈疭uperh銆?/p>

聽宓屽叆寮忓井澶勭悊鍣ㄧ殑閫夊瀷鍘熷垯: 1)璋冩煡甯傚満涓婂凡鏈夌殑cpu渚涘簲鍟嗐€?)聽cpu鐨勫鐞嗛€熷害銆?3)鎶€鏈寚鏍囥€?4)澶勭悊鍣ㄧ殑浣庡姛鑰椼€?5)澶勭悊鍣ㄧ殑杞欢鏀寔宸ュ叿銆?6)澶勭悊鍣ㄦ槸鍚﹀唴缃皟璇曞伐鍏峰拰澶勭悊鍣ㄤ緵搴斿晢鏄惁鎻愪緵璇勪及鏉裤€?/p>

聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 鍥?.1聽鍗曟澘璁$畻鏈?/p>

聽 聽 閫夋嫨涓€涓祵鍏ュ紡绯荤粺杩愯鎵€闇€瑕佺殑寰鐞嗗櫒锛屽湪寰堝鏃跺€欒繍绠楅€熷害骞朵笉鏄渶閲嶈鐨勮€冭檻鍐呭锛屾湁鏃跺€欎篃蹇呴』鑰冭檻寰鐞嗗櫒鍒堕€犲巶鍟嗗浜庤鍎囧鍩嬪櫒鐨勬枃鎸佹€佸害锛屾湁浜涘祵鍏ュ紡绯荤粺浜у搧涓€鐢ㄥ氨鏄嚑鍗佸勾锛屽鏋滆繃浜嗕簲鍏勾涔嬪悗闇€瑕佺淮淇紝鍗村凡缁忔壘涓嶅埌璇ョ寰鐞嗗櫒鐨勮瘽锛屽娍蹇呭叏閮ㄤ骇鍝侀兘瑕佹窐姹帮紝鎵€浠ヨ澶氫笓闂ㄧ敓浜у祵鍏ュ紡绯荤粺寰鐞嗗櫒鐨勫巶鍟嗭紝閮戒細涓哄祵鍏ュ紡绯荤粺鐨勫井澶勭悊鍣ㄧ暀涓嬭冻澶熺殑搴撳瓨鎴栨槸鐢熶骇绾匡紝鍗充娇杩囧ソ鍑犲勾涔嬪悗杩樺彲浠ユ壘鍒扮浉鍚屽瀷鍙风殑寰鐞嗗櫒鎴栬€呭畬鍏ㄥ吋瀹圭殑鏇夸唬鍝併€?/p>

聽 聽聽

聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽鍥剧ず涓猴細宓屽叆寮忓井鎺у埗鍣紙宸︼級鍜屽井鎺у埗鍣ㄨ姱鐗囧唴閮ㄥ浘

聽 聽 鎴戜滑瀵逛笂鍥捐繘琛屼竴涓嬭в璇伙紝宓屽叆寮忓井鎺у埗鍣ㄦ垜浠張绉颁负鍗曠墖鏈猴紝浠栧凡缁忓皢鎴戜滑鏁翠竴涓绠楁満绯荤粺闆嗘垚鍒颁竴鍧楄姱鐗囦笂闈簡銆?/p>

聽 聽宓屽叆寮忓井鎺у埗鍣ㄤ竴鑸互鏌愪竴 绉嶅井澶勭悊鍣ㄥ唴鏍镐负鏍稿績锛岃姱鐗囧唴閮ㄩ泦鎴怰om/eprom銆丷am銆?鎬荤嚎銆佹€荤嚎閫昏緫銆佸畾鏃?璁℃暟鍣ㄣ€乄atchdog銆?i/o銆?涓茶鍙c€佽剦瀹借皟鍒惰緭鍑恒€丄/d銆?d/a銆?flash ram銆丒eprom 绛夊悇绉嶅繀瑕佸姛鑳藉拰澶栬銆備负閫傚簲涓嶅悓鐨勫簲鐢ㄩ渶姹傦紝-鑸? 涓?绯诲垪鐨?鍗曠墖鏈哄叿鏈夊绉嶈鐢熶骇鍝侊紝 姣忕琛嶇敓浜у搧鐨勫鐞嗗櫒鍐呮牳閮芥槸涓€鏍风殑锛屼笉鍚岀殑鏄瓨鍌ㄥ櫒鍜屽璁剧殑閰嶇疆鍙婂皝瑁呫€傝繖鏍峰彲浠ヤ娇鍗曠墖鏈烘渶澶ч檺搴﹀拰搴旂敤闇€姹傜浉鍖归厤锛屽姛鑳戒笉澶氫笉灏戯紝浠庤€屽噺灏戝姛鑰楀拰鎴愭湰銆?聽 聽鍜屽祵鍏ュ紡寰鐞嗗櫒鐩告瘮锛屽井鎺у埗鍣ㄧ殑鏈€澶х壒鐐规槸鍗曠墖鍖栵紝浣撶н澶уぇ鍑忓皬锛屼粠鑰屼娇鍔熻€楀拰鎴愭湰涓嬮檷銆佸彲闈犳€ф彁楂樸€傚井鎺у埗鍣ㄦ槸鐩墠宓屽叆寮忕郴缁熷伐涓氱殑涓绘祦銆傚井鎺у埗鍣ㄧ殑鐗囦笂澶栬璧勬簮涓€鑸瘮杈冧赴瀵岋紝 閫傚悎浜庢帶鍒讹紝鍥犳绉板井鎺у埗鍣ㄣ€傚祵鍏ュ紡寰帶鍒跺櫒 鐩墠鐨勫搧绉嶅拰鏁伴噺鏈€澶氾紝姣旇緝鏈変唬琛ㄦ€х殑閫氱敤绯诲垪鍖呮嫭8051銆丳51xa銆丮cs -251銆丮cs- -96/196/296銆丆166/167銆丮c68hc05/11/12/16銆?68300銆佹暟鐩紬澶欰rm鑺墖绛夈€傜洰鍓峂cu鍗犲祵鍏ュ紡绯荤粺绾?0%鐨勫競鍦轰唤棰濄€?/p>

聽 聽褰撶劧锛岀敱浜庢妧鏈湁闄愶紝鐩墠鑳芥兂鍒扮殑锛岃兘鏌ュ埌鐨勭煡璇嗙偣鍙湁閭d箞涓€浜涳紝鍚戞洿鍔犳繁鍏ヤ簡瑙g殑璇昏€呬滑鍙互鍒扮浉鍏崇殑缃戠珯銆佷功绫嶄互鍙婅棰戣绛夌瓑鎵ф煡闃咃紒

stm32f40x鏈€灏忕郴缁?/p>

姒傚康锛氫粈涔堟槸鏈€灏忕郴缁燂紵聽鏈€灏忕郴缁熸寚鐨勬槸锛氳兘澶熻mcu宸ヤ綔鐨勬渶灏忕粍鎴愬崟浣嶏紱缁撴瀯:鐗囧唴/鐗囦笂澶栬銆佹澘涓婂璁撅紱鎴戜滑鍙互鐪嬩竴涓嬪紑鍙戞澘鐨勬澘涓婂璁撅細

缁撴瀯:鐗囧唴/鐗囦笂澶栬銆佹澘涓婂璁撅紱

澶ц嚧濡備笂锛氱壒娈婂崟鍏冩湁濡傚彸杈圭殑澶嶄綅鐢佃矾銆侀渿鑽$數璺紝绉颁负鏉夸笂鐢佃矾銆傚姞涓婄墖涓婂璁撅紝缁勬垚鑺墖銆?/p>

鏈€灏忕郴缁熺粍鎴愰渶瑕佸摢浜涢儴鍒嗭紵

鐢垫簮閮ㄥ垎锛氬綋鍓嶄娇鐢ㄧ殑鑺墖閲囩敤鐨勬槸coms鐢靛钩锛?.3v渚涚數锛夛紱鎸崱鐢佃矾锛氳兘澶熻mcu宸ヤ綔蹇冭烦浜х敓璧锋潵鐨勭數璺€備竴鑸繖鏍风殑鐢佃矾瀛樺湪鏈夊緢澶氱锛屾瘮濡俁c鎸崱鍣ㄣ€佹櫠鎸瓑绛夛紱澶嶄綅鐢佃矾锛毬犳蹇?-鑳藉璁㎝cu閲嶆柊浠巑ain鍑芥暟寮€濮嬫墽琛岀殑鐢佃矾锛涗竴鑸繖鏍风殑澶嶄綅鐢佃矾鍙互鍒嗘垚寰堝绉嶏細姣斿杞‖浠跺浣嶃€佺湅闂ㄧ嫍锛圵dg锛夊浣嶇瓑绛夛紱涓昏瑕佹帉鎻$殑鏄‖浠跺浣嶏細鏉夸笂澶栬鑳藉璁㎝cu澶嶄綅鐨勭數璺€傛瘮濡傦細浣犵殑鏉垮瓙鍗′綇浜嗭紝灏遍渶瑕佷竴涓寜閿繘琛屾澘瀛愮殑澶嶄綅閲嶆柊寮€濮嬪伐浣滐紝杩欐牱鐨勭數璺紝灏辨垚涓虹‖浠跺浣嶃€備緥濡傦細閲嶅惎閿紝涓嬪浘涓哄浣嶇數璺ず渚嬪浘

4. 鍚姩鏂瑰紡锛歋tm32f40x鑺墖鍚姩鐨勬柟寮忔湁寰堝绉嶏紝鍙互鏍规嵁鑷繁鐨勯渶瑕佽繘琛岄€夋嫨锛?/p>

瑙i噴锛氬綋boot1:boot0涓篨 0鐨勬椂鍊欙紝杩欐椂鍊欑殑鍚姩鏂瑰紡涓郝犱粠涓籉lash鍚姩锛孧uc鍙互姝e父鎵ц宸ヤ綔锛?/p>

聽 聽 聽 聽 聽 褰揃oot1:boot0涓? 1鐨勬椂鍊欙紝杩欐椂鍊欑殑鍚姩鏂瑰紡涓?浠庣郴缁熷瓨鍌ㄥ櫒鍚姩锛屼絾鏄▼搴忓彲浠ヨ繘琛岀儳褰曪紝浣嗘槸涓嶈兘鎵ц锛?/p>

聽 聽 聽 聽 聽聽褰揃oot1:boot0涓?聽1鐨勬椂鍊欙紝杩欐椂鍊欑殑鍚姩鏂瑰紡涓?浠庡祵鍏ュ紡sram鍚姩锛屼笖绋嬪簭鍙互杩涜鐑у綍鍜岃繘琛屼唬鐮佹墽琛岋紱浣嗘槸鎸変笅澶嶄綅閿殑鏃跺€欙紝绋嬪簭涓嶄細鎵ц锛屼唬鐮佷細涓㈠け锛屽洜涓哄綋浣犳寜涓嬪浣嶉敭鐨勬椂鍊欙紝鐢垫簮灏变細鏂數锛屽洜姝や唬鐮佺▼搴忎篃浼氳窡鐫€涓㈠け銆?/p>

鍥犳锛岃鑺墖锛圫tm32f407zgt6涓轰緥锛岀郴鍒楄姱鐗囧樊涓嶅锛夋渶濂界敤鐨勬槸x0鐨勬柟寮忚繘琛屽惎鍔ㄣ€傚綋鐒讹紝褰撶▼搴忎笅杞芥湁鏌愮閿欒鏃犳硶鎿嶄綔鐨勬椂鍊欙紝鍙互杩涜鍚姩鏂瑰紡鐨勮皟鏁达紝杩欐牱鍚庨潰灏卞彲浠ヨ繘琛屼笅杞界儳褰曚簡銆?/p>

聽 聽 聽

聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽

1銆佹惌寤哄紑鍙戠幆澧?/p>

1.寮€鍙戣鏄?/p>

聽 鎴戜滑寮€鍙戜竴涓姛鑳介鍏堢涓€姝ュ氨鏄啓鍚勭鍚勬牱涓嶅悓妯″潡鐨勭▼搴忥紝浣嗘槸鍦ㄥ啓绋嬪簭妯″潡涔嬪墠锛屾垜浠鐨勬槸鎼缓涓€涓紪绋嬬殑寮€鍙戠殑寮€鍙戠幆澧冿紝鎴戜滑瑕佸畨瑁呯殑寮€鍙戠殑杞欢缂栫▼鐜灏辨槸鎴戜滑鐨刱eil5杩欎釜缂栫▼杞欢銆傝窡鐫€鎴戠殑鑴氭锛屾垜浠竴姝ユ鐨勫畨瑁呰繖涓紪绋嬭蒋浠躲€?/p>

杩欎釜鏂囦欢鍖呭ぇ瀹跺彲浠ュ埌stm32瀹樼綉涓婇潰鑷涓嬭浇锛屼篃涓嶅ぇ灏?00鏉锛屾垜浠彲浠ョ湅鍒颁笂闈紝鈥滆姱鐗囨敮鎸佸寘鈥濓紝閲岄潰鍖呭惈浣跨敤鐨勬槸鎴戜滑鐨勮姱鐗囷紝涓€涓伐绋嬭鎼缓璧锋潵聽涓€瀹氭墍闇€鐨勫氨鏄棶鎴戜滑鐨勮姱鐗囧寘銆傛渶涓嬮潰鐨勪袱涓槸鎴戜滑涓嬭浇鐨勯┍鍔紝涓€涓彲浠ユ敮鎸亀in7銆亀in0绯荤粺銆傚ぇ瀹跺彲浠ユ牴鎹嚜宸辩殑鐢佃剳鐨勯厤缃嚜琛岄€夋嫨涓嬭浇锛岃繖涓€浜涜祫婧愬悗缁湁闇€瑕佺殑鍙互绉佽亰锛岄渶瑕佷粈涔堥兘浼氳繘琛屽垎浜紝鎴栬€呭ぇ瀹跺彲浠ヨ嚜琛屽埌瀹樼綉涓嬭浇锛岃繖鏍锋洿鍔犵洿鎺ヤ簡褰撱€?/p>

1.1杞欢瀹夎

鎴戜滑涓婅堪鐨勮蒋浠跺畨瑁呭寘杩涜鍒拌繖閲岋紝鎴戜滑鐩存帴鍙屽嚮鐐瑰嚮mdk杩涜杩愯瀹夎锛岀劧鍚庡氨浼氬嚭鐜板埌涓€涓嬬殑杩欎釜鐣岄潰锛岀劧鍚庢帴鐫€鎴戜滑鐐瑰嚮next灏卞ソ浜嗐€?/p>

聽涓嬩竴姝ワ紝鎴戜滑鍕句笂鈥滃悓鎰忊€濓紝鍐嶆帴鐫€next灏卞ソ浜嗭紱

鎺ヤ笅鏉ュ嚭鐜扮殑鐣岄潰鏄鎴戜滑瀹夎鐨勫湴鏂癸紝澶у鎵ц嚜琛屽畨瑁呭埌鑷繁鎯宠瀛樻斁鐨勪綅缃氨鍙互浜嗭紝鏈€濂戒笉瑕佸畨瑁呭埌绯荤粺鐩橈紝涔熸渶濂戒笉鐢ㄤ娇鐢ㄤ腑鏂囥€佷笉瑕佹湁绌烘牸锛屽洜涓轰腑鏂囩┖鏍兼湁鏃跺€欎細鍑虹幇閿欒锛屽綋鐒跺嚭鐜扮殑鍑犵巼寰堝皬锛屼絾鏄垜浠繕鏄弗璋ㄤ竴鐐逛负濂姐€?/p>

鎺ヤ笅鏉ュ氨鍒拌繖涓晫闈紝閲岄潰鐨勫弬鏁版垜浠彲浠ラ殢鎰忎慨鏀癸紝浣嗘槸杩樻槸涓嶈鏈変腑鏂囷紱

鍒拌繖閲屽悗灏眓ext锛岀劧鍚庡氨鍙互杩涜鍒板畨瑁呰蒋浠朵簡锛?/p>

鎺ヤ笅閲屼細鍑虹幇涓€涓繖鏍风殑鐣岄潰锛屾垜浠渶瑕佺殑鏄鎶婅繖涓€夐」鍕鹃€変笂鐨勫幓鎺夛紝鍥犱负濡傛灉浣犻€夋嫨浠栫殑璇濓紝瀹冨氨浼氳嚜鍔ㄥ府浣犺繍琛屽伐绋嬶紱

涓嬭浇瀹夎瀹屾垚涔嬪悗锛屾垜浠氨浼氱湅鍒扮數鑴戣嚜鍔ㄥ脊鍑鸿繖鏍风殑涓€涓晫闈紝鎴戜滑涓嶉渶瑕佺悊浼氾紝涔熶笉闇€瑕佷换浣曠殑鎿嶄綔锛岀洿鎺ュ叧鎺夊氨濂戒簡锛屽洜涓烘垜浠繖涓楠ゆ病鏈変粈涔堜笢瑗块渶瑕佹垜浠繘琛屾敼鍔ㄧ殑锛岀劧鍚庢垜浠殑杞欢灏卞畨瑁呭畬姣曚簡锛?/p>

聽鐒跺悗鎴戜滑灏卞彲浠ュ湪鎴戜滑鐨勬闈笂鐪嬪埌鎴戜滑鐨勮蒋浠剁殑鍥炬爣锛岃〃绀哄畨瑁呭凡缁忓叏閮ㄥ畬鎴愶紱

2. 杞欢娉ㄥ唽聽

鍦ㄦ垜浠垰鍒氱殑鏂囦欢澶逛笅闈㈡垜浠壘鍒拌繖涓敞鍐屾満锛屾垜浠洿鎺ュ弻鍑昏繘琛岃繍琛屾敞鍐岋紱

鎺ヤ笅鏉ユ垜浠彸閿?鍗曞嚮鎴戜滑鍒氬垰涓嬭浇鐨刱eil5杞欢锛岀劧鍚庝互鈥滅鐞嗗憳韬唤杩愯鈥濓紱

鐒跺悗鎴戜滑鍒発eil5閲岄潰鍦ㄦ垜浠殑file杩欎竴鏍忔垜浠偣鍑婚€夋嫨鈥渓icense鈥濊繖涓€鏍忥紝

鐐瑰嚮涔嬪悗鎴戜滑鏈轰細杩涘埌涓嬮潰杩欎釜鐣岄潰锛岃繖涓槸鎴戜滑鐨勮蒋浠舵敞鍐岀殑鐣岄潰锛?/p>

聽鐒跺悗涓嬮潰鐨勬敞鍐屾満涓婇潰鐨勬搷浣滃ぇ瀹舵寜鐓т笅闈㈠浘绀虹殑姝ラ鎿嶄綔灏卞彲浠ヤ簡锛岃繖閲屽浘绀烘瘮鏂囧瓧鏇村姞鐨勮缁嗭紱

鍒拌繖涓湴鏂癸紝鎴戜滑鐨勮蒋浠剁殑瀹夎鍔犱笂鎴戜滑娉ㄥ唽鏈虹殑娉ㄥ唽灏卞畬鎴愪簡锛?/p>

3.瀹夎鐩稿簲鐨勮姱鐗囧寘聽

聽鏀硅鏂囩珷鎴戜滑浣跨敤鐨勬槸stm32f407zgt6锛屾垜浠氨瑕佸畨瑁呯浉瀵瑰簲鐨勮姱鐗囧寘锛岋紙绗竴涓槸f4绯诲垪鐨勶紝绗簩涓槸瀹屾暣鐨勮姱鐗囧寘锛?/p>

鎴戜滑鐨勭涓€姝ュ氨鏄洿鎺ヨ繍琛屾垜浠殑keli.stm32f4xx_dfp.2.7.0杩欎釜鍖咃紝鐒跺悗鎴戜滑灏卞彲浠ョ湅鍒颁笅闈㈢殑杩欎釜鐣岄潰锛?/p>

鍦ㄦ垜浠瓑寰呬竴娈垫椂闂翠箣鍚庡氨浼氬嚭鐜拌繖鏍风殑涓€涓晫闈紝鎴戜滑涓嶉渶瑕佽繘琛屼换浣曠殑鎿嶄綔锛屾垜浠洿鎺ext灏卞ソ浜嗭紝涓嬩竴姝ワ紝灏变細杩涜鎴戜滑鑺墖鍖呯殑瀹夎锛屾垜浠彧闇€瑕佺瓑寰呬笅杞藉畬鎴愬氨濂戒簡锛涘涓嬪浘鎵€绀?/p>

4.瀹夎涓嬭浇鍣ㄩ┍鍔?/p>

鍥犱负鎴戜滑鍐欏ソ浠g爜锛屾垜浠闇€瑕佸皢浠g爜鐑у綍鍒版垜浠殑鏉垮瓙锛屾墍浠ユ垜浠渶瑕佸畨瑁呬竴涓彲浠ヤ笅杞界殑椹卞姩锛屾垜浠繖閲岀敤鐨勬槸st-link,鎴戜滑鍙互鏍规嵁鑷繁鐨勭郴缁熻繘琛屼笅杞戒笉鍚岀殑椹卞姩锛?/p>

鎴戜滑杩欎竴绡囨枃绔犳垜浠娇鐢ㄧ殑鏄痺in10锛屾墍浠ヨ繖閲屽氨浣跨敤win10锛屽涓嬪浘锛屾垜浠偣鍑荤殑鏄痺in19鐨勯┍鍔紝鎴戜滑灏变細灏变細杩涘叆鍒版垜浠繖鏍风殑涓€涓晫闈紱

鎺ョ潃鎴戜滑灏变細寮瑰嚭杩欐牱鐨勪竴涓晫闈紱

鎴戜滑鍙渶瑕佺偣鍑籲ext灏卞彲浠ヤ簡锛?/p>

褰撳嚭鐜拌繖鏍风殑涓€涓晫闈紝杩欐牱灏遍┍鍔ㄥ畨瑁呭畬鎴愩€傝矾寰勫叏閮ㄩ兘閫夋嫨榛樿鐨勮矾寰勶紝涓嶉渶瑕佽繘琛屼换浣曟搷浣滐紝涓嬩竴姝ワ紝鎴戜滑鎬庝箞妫€鏌ユ槸鍚﹀畨瑁呮垚鍔熷憿锛屾垜浠數鑴戣劯涓奡t-link锛屾墦寮€鎴戜滑鐨勮澶囩鐞嗗櫒锛屽嚭鐜拌繖鏍风殑锛岄偅涔堟垜浠繖涓伐绋嬬殑鍓嶆湡宸ヤ綔灏辫〃绀哄畨瑁呮垚鍔熶簡銆?/p>

褰撶劧涓嶄唬琛ㄨ繖鏍峰氨鎴愬姛浜嗭紝鍙湁椹卞姩鐨勭伅涓嶉棯鐑侊紝鎵嶇畻鏄畨瑁呮垚鍔燂紝鐏鑹插浐瀹氫负绾㈣壊锛屼笉闂儊鍗冲彲銆?/p>

杩欎竴涓畨瑁呯殑姝ラ閮芥槸鍗氫富寰€鏈熺殑鍗氬锛屽ぇ瀹舵兂鐪嬬畝鍗曠殑锛屽彲浠ョ綉椤佃繘琛屾悳绱㈠氨濂戒簡銆傜浉鍏崇殑閾炬帴濡備笅锛氭湰鏂囬摼鎺ワ細銆怌ortex-m4銆戝涔?day1 鎼缓寮€鍙戠幆澧僟涓樻瘮鐗规儵缃氶檰鐨勫崥瀹?csdn鍗氬

2銆丟pio瀹為獙聽

2.1gpio姒傝堪

聽 聽 gpio鎺ュ彛鎸囩殑鏄€氱敤杈撳叆/杈撳嚭鎺ュ彛銆傞€氫織鐨勮锛岄偅灏辨槸鑺墖鐨勫紩鑴氾紝鍙互閫氳繃浠栦滑杈撳叆楂樼數骞虫垨鑰呬綆鐢靛钩锛屼篃鍙互閫氳繃璇诲叆浠栦滑鐨勫紩鑴氱殑鐢靛钩鐘舵€?-鍒板簳鏄珮杩樻槸浣庣數骞炽€侴pio鍙o細绠€鍗曡€岃█锛屽氨鏄姱鐗囩敤鏉ユ帶鍒舵垨鑰呴噰闆嗗閮ㄥ櫒浠剁殑鐩稿叧淇℃伅锛岃繖涓張鍙互绉颁箣涓鸿緭鍏ヨ緭鍑虹殑绔彛銆?/p>

聽 聽閭pio鐨勪綔鐢ㄦ槸浠€涔堝憿锛熸槸鑺墖鐢ㄦ潵鎰熺煡澶栭儴涓栫晫骞朵笖鐢ㄦ潵鎺у埗澶栭儴涓栫晫鐨勫獟浠嬶紱

鍦ㄦ垜浠殑stm32涓紝gpio鍙d竴鍏辨湁114涓紝鑰屼笖杩?14涓狦pio鍙d互鍒嗙粍鐨勫舰寮忓瓨鍦紝濡備笅鍥炬墍绀猴細鎴戜滑鐢辫繖涓姱鐗囧唴閮ㄧ粨鏋勬鏋惰繖涓浘锛圫tm32f407xx锛夛紝鎴戜滑鍙互鐭ラ亾gpio鍙o紝浼氭寜鐓у垎缁勭殑褰㈠紡瀛樺湪銆?/p>

聽 濡備笅鍥撅紝鍒嗗埆鍙互浠嶨pioa鍒癎pioi鍙o紝浣嗘槸涓婅堪鐨勭粨鏋勬鏋跺浘鏄疐407绯诲垪鐨勶紝鐜板湪璁扮瑪璁扮殑鑺墖涓篠tm32f407zgtx鑺墖锛屾墍浠ヤ笂杩扮殑鍒嗙粍娌℃湁閭d箞澶氾紝鍙惈鏈夊垎閰嶅埌浠嶨pioa--gpiog涓€鍏?缁勶紝姣忎竴缁?6涓狪o鍙o紝鍙互濡備笂缁撴瀯妗嗘灦鍥惧彲浠ョ煡閬撲粠0鍙?-15鍙o紝涓€鍏卞崄鍏釜锛屾墍浠ヤ竴鍏辨€诲緱gpio鍙d竴鍏辨槸112涓€?/p>

聽聽

聽 聽 聽 聽 聽 聽 stm32f407zgt6鑺墖

聽杩樻湁涓や釜鍒嗗埆鏄紝鎴戜滑鍙互浠庣數璺浘鍙互鎵惧埌锛屽洜涓鸿繖涓や釜io鍙f瘮杈冪壒娈婏紝涓嶇敤鎴戜滑鐩存帴鎿嶄綔鐨勶紝鎵€浠ュ彲浠ヤ笉绠楀埌缁撴瀯鍥惧綋涓潵锛屾垜浠彲浠ヤ簡瑙d竴涓嬶紝鍒嗗埆濡備笅锛?/p>

鍙︿竴涓篃鏄湪cpu鍙宠竟锛岃繖涓狪o鍙f槸鐢垫睜绠$悊銆?/p>

聽鎵╁睍姣旇緝涓€涓嬶紝鐩告瘮浜嶴tm32锛屾垜浠殑51鍗曠墖鏈虹殑io鍙d篃鏄寜鐓у垎缁勭殑褰㈠紡瀛樺湪鐨勶紝鍒嗗埆浠嶱0-p3缁勶紝鑰屼笖姣忎竴缁処o鍙i兘鏈?涓彛锛屽垎鍒敱p0.0-p0.7.

2.2 gpio鐨勪富瑕佺壒寰?/p>

鍙楁帶io鍙e杈惧崄鍏釜锛屾瘡涓€缁勬湁16涓狪o鍙o紱杈撳嚭鐘舵€侊細鎺ㄦ尳鎴栬€呭紑婕?涓婃媺鎴栦笅鎷変粠杈撳嚭鏁版嵁瀵勫瓨鍣紙gpiox_odr锛夋垨澶栬锛堝鐢ㄥ姛鑳借緭鍑猴級杈撳嚭鏁版嵁锛涘彲浠ヤ负姣忎竴涓狪o閫夋嫨涓嶅悓鐨勯€熷害锛涜緭鍏ョ姸鎬侊細娴┖銆佷笂涓嬫媺銆佹ā鎷熻緭鍏ワ紙鏁版ā杞崲鍣級锛涘皢鏁版嵁杈撳叆鍒拌緭鍏ユ暟鎹瘎瀛樺櫒锛圙piox_odr锛夋垨澶栬锛堝鐢ㄥ姛鑳借緭鍏ワ級锛堣繖閲岀畝鍗曡€岃█锛屾垜浠噰闆嗗闈㈢殑淇℃伅锛屾斁鍒板摢閲屽幓锛屽氨鏄垜浠殑杈撳叆鏁版嵁瀵勫瓨鍣ㄤ腑锛夛紱缃綅鎴栬€呭浣嶅瘎瀛樺櫒锛圙piox_bsrr锛夛紝瀵笹piox_odr鍏锋湁鎸変綅鍐欐潈闄愶紱閿佸畾鏈哄埗锛圙piox_lckr锛夛紝鍙喕缁揑o閰嶇疆锛堣繖浜涚畝鍗曠悊瑙e氨鏄瘮濡傛垜浠敤寮曡剼鎺у埗鐏紝鎴戜滑灏辨槸鍙敤涓€涓紩鑴氬氨鍙互浜嗭紝鍚庨潰涓嶇敤鏀瑰彉杩欎釜寮曡剼锛岀劧鍚庢垜浠氨鍙互灏嗚繖涓紩鑴氭敼鎴愬喕缁撻厤缃ā寮忥紝濂藉灏辨槸鎴戜滑涓嶅皬蹇冪浜嗕竴涓紩鑴氳浆鎬侊紝杩欎釜鍐荤粨灏卞彲浠ュ府鎴戜滑閿佸畾锛屼笉鐒跺浐瀹氬姛鑳藉洜姝ゆ敼鍙橈級锛涘惈鏈夋ā鎷熷姛鑳斤紱澶嶇敤鍔熻兘杈撳叆/杈撳嚭閫夋嫨瀵勫瓨鍣紙涓€涓狪o鍙f渶澶氬彲浠ユ湁鍗佸叚涓鐢ㄥ姛鑳斤紝鍜?1涓嶄竴鏍凤紝鎴戜滑姣忎竴涓狪o鍙i兘鏈夊鐢ㄥ姛鑳斤級锛堣繖閲岀畝鍗曠悊瑙e氨鏄垜浠墍璋撶殑澶嶇敤灏辨槸闄や簡gpio鎴戜滑杩樻湁寰堝鐨勫緢澶氾紝濡備笅鍥炬墍绀猴紝timx銆丼pi绛夌瓑锛夛紱蹇€熺炕杞紝姣忔缈昏浆鏈€澶氬彧闇€瑕佷袱涓椂閽熷懆鏈燂紱寮曡剼澶嶇敤闈炲父鐏垫椿锛屽厑璁稿皢io寮曡剼鐢ㄤ綔gpio鎴栧绉嶅璁惧姛鑳戒腑鐨勪竴绉嶏紱

鎴戜滑鍜屾垜浠殑51鍗曠墖鏈虹浉浜掓瘮杈冧竴鏍凤紝灏变細鍙戠幇鍜?1鐨処o鍙d笉涓€鏍凤紝鎴戜滑涓嬪浘鍥剧ず姣旇緝涓€涓嬶細

聽濡備笂鍦堣捣鏉ョ殑瑙i噴锛?1鍗曠墖鏈鸿繖涓狿3鍙湁p3.0鍜孯xd杩欎袱涓姛鑳斤紝鎵€浠ユ垜浠殑stm32鐨凣pio鍙g敤璧锋潵鏇村姞鐨勭伒娲汇€?/p>

2.3 鍙橀噺鍜屽瘎瀛樺櫒

鎴戜滑璇翠竴涓嬭繖涓や釜涓嶅悓浠ュ強鐩稿悓鐨勫湴鏂癸紝浜岃€呯浉鍚岀殑鍦版柟锛氬彉閲忓拰瀵勫瓨鍣ㄤ竴鏍烽兘鏄悜鍐呭瓨鐢宠浜嗗瓨鍌ㄧ殑绌洪棿锛屽彲浠ュ瓨鍌ㄦ暟鎹紝骞朵笖杩樻湁鐩稿簲鐨勫湴鍧€锛?/p>

浜岃€呭瓨鍦ㄥ樊寮傜殑鍦版柟锛氬彉閲忕殑鍦板潃鏄殢鏃跺彉鍖栫殑锛屼絾鏄瘎瀛樺櫒鐨勫湴鍧€鏄笉鍙樼殑锛岀畝鍗曡锛屽瘎瀛樺櫒鐨勫湴鍧€宸茬粡琚垜浠殑鑺墖缁欏浐瀹氬ソ浜嗐€?/p>

渚嬪锛?/p>

聽 聽鍙橀噺鎴戜滑鐢ㄤ竴涓釜灏忕殑锛堝彸涓嬭锛夋柟妗嗚〃绀猴紝璁╁悗杩欎釜鍙橀噺鏄彲浠ユ敼鍙樼殑锛屽彲浠ヨ繘琛屽乏绉诲彸绉荤瓑鎿嶄綔锛屼絾鏄垜浠殑瀵勫瓨鍣紝瀵勫瓨鍣ㄧ浉褰撲簬鍙橀噺锛屽彉閲忓氨浼氭湁鍙橀噺鍚嶏紝鍙橀噺鍚嶅氨鏈夊湴鍧€锛屽彧涓嶈繃鎴戜滑鐨勫瘎瀛樺櫒鐨勫湴鍧€鏄浐瀹氱殑锛堝涓婃垜浠缃垚0x32锛夛紝鎵€浠?x32灏辨槸鎴戜滑瀵勫瓨鍣ㄧ殑鍚嶅瓧銆?/p>

2.4 gpio瀹為獙锛堟寜閿偣浜甃ed鐏級

聽 鎴戜滑閫氳繃涓嬮潰鐨勭數璺浘锛屾垜浠彲浠ョ湅鍒板洓涓伅鐨勫紩鑴氬垎鍒槸pf9銆丳f10銆丳f6銆丳c0锛屾垜浠洿鎺ヨ繘琛屽畯瀹氫箟杩欎竴浜涘紩鑴氬氨鍙互浜嗭紝榛樿涓洪珮鐢靛钩锛岀數骞充綆鐐逛寒锛?/p>

聽杩涜鐏殑瀹忓畾涔夛細锛堣繖閲岀洿鎺ュ湪鎴戜滑鐨刴ain.c杩涜瀹忓畾涔夛級

#define led1 pfout(9)

#define led2 pfout(10)

#define led3 pfout(6)

#define led4 pcout(0)

鐒跺悗鎴戜滑鍐嶇湅鐪嬫垜浠殑鎸夐敭锛?/p>

鏈夎繖涓浘鎴戜滑鐩存帴鍙互鍦ㄦ垜浠殑main.c杩涜鎸夐敭鐨勫畯瀹氫箟灏卞彲浠ヤ簡锛?/p>

#define key1 pain(0)

#define key2 pein(2)

#define key3 pein(3)

#define key4 pein(4)

led.c

鏂板缓涓€涓枃浠讹紝鎴戜滑鍛藉悕涓簃ain.c聽鏉ラ厤缃垜浠伅鐨勫垵濮嬪寲聽led_init锛岀劧鍚庢垜浠繘琛岀浉搴旂殑閰嶇疆灏卞ソ浜嗭紱

#include "led.h"

void led_init(void)

{

gpio_inittypedef led;

rcc_ahb1periphclockcmd(rcc_ahb1periph_gpioc, enable); //浣胯兘gpioc

rcc_ahb1periphclockcmd(rcc_ahb1periph_gpiof, enable); //浣胯兘gpioc

led.gpio_mode=gpio_mode_out; //杈撳嚭

led.gpio_otype=gpio_otype_pp; //鎺ㄦ尳

led.gpio_pin=gpio_pin_0; //寮曡剼

led.gpio_pupd=gpio_pupd_up; //涓婃媺

led.gpio_speed=gpio_speed_100mhz;

gpio_init(gpioc,&led);

led.gpio_mode=gpio_mode_out; //杈撳嚭

led.gpio_otype=gpio_otype_pp; //鎺ㄦ尳

led.gpio_pin=gpio_pin_6|gpio_pin_9|gpio_pin_10; //寮曡剼6/9/10

led.gpio_pupd=gpio_pupd_up; //涓婃媺

led.gpio_speed=gpio_speed_100mhz;

gpio_init(gpiof,&led);

gpio_setbits(gpioc, gpio_pin_0); //缁欏埌楂樼數骞筹紝鍥犱负鎴戜滑鍓嶉潰璇翠簡鐢佃矾涓轰綆鐢靛钩鐐逛寒

gpio_setbits(gpiof, gpio_pin_6|gpio_pin_9|gpio_pin_10);

}

key.c聽 鎿嶄綔杩樻槸璺熶笂闈㈢殑锛岄厤缃浉搴旂殑鏃堕挓銆佸姛鑳界瓑绛夛紱涓嶈繃澶氱殑浠嬬粛锛屽洜涓哄線鏈熺殑鍗氬宸茬粡鏈夛紝鑰屼笖杩欎釜涓滆タ鐩稿鐨勭畝鍗曪紝灏变笉璁蹭簡锛?/p>

鐒跺悗鎴戜滑鍦ㄥ嚱鏁拌繘琛岃皟鐢ㄥ氨鍙互浜嗭紒濡備笅鍥撅細

聽杩欐牱鎴戜滑鐨勪竴涓寜閿偣浜垜浠琇ed鐏殑灏忓疄楠屽氨鍙互瀹屾垚浜嗭紝鐩稿叧鐨勯」鐩枃浠跺す鍚庨潰鏈夐渶瑕佺殑璇濆彲浠ョ鑱婏紒

3銆佷腑鏂疄楠?/p>

3.1涓柇绠€浠?/p>

3.1.1涓柇姒傚康

浠€涔堟槸涓柇锛熶腑鏂氨鏄疌pu鍦ㄦ甯歌繍琛岀▼搴忕殑鏃跺€欙紝鐢变簬鍐呴儴鎴栬€呭閮ㄤ簨浠跺紩璧风殑鏆傛椂涓鐜拌鐨勭▼搴忥紝杞幓鎵ц璇锋眰cpu涓哄叾鏈嶅姟鐨勯偅涓璁炬垨鑰呬簨浠剁殑鏈嶅姟绋嬪簭锛岀瓑寰呰繖涓湇鍔$▼搴忔墽琛屽畬姣曞張瑕佽繑鍥炲埌琚腑姝㈢殑鍦版柟鐨勭▼搴忥紝杩欎箞鐨勪竴涓繃绋嬨€傛垜锛屼滑鍙互鏍规嵁涓€涓嬬殑娴佺▼鍥捐繘琛屼竴涓嬫弿杩帮細

涓柇鎵ц娴佺▼鍥?

聽涓柇鎸囩殑寰堢畝鍗曪紝鎸囩殑鏄湪鎴戜滑鐨凜pu鎵ц姝e父鐨勭▼搴忕殑鏃跺€欙紝鐢变簬澶栭儴鎴栬€呭唴閮ㄤ簨浠舵垨鐢辩▼搴忛鍏堝畨鎺掔殑浜嬩欢锛屽紩璧风殑cpu涓柇姝e湪杩愯鐨勭▼搴忥紝鑰岃浆鍒颁负澶栭儴鎴栧唴閮ㄤ簨浠舵湁绋嬪簭棰勫厛瀹夋帓鐨勪簨浠舵湇鍔$殑绋嬪簭涓幓锛屾湇鍔″畬姣曪紝鍐嶈繑鍥炲埌鎵ц鏆傛椂涓柇鐨勭▼搴忋€?/p>

3.1.2 涓柇鎰忎箟

涓柇锛岀▼搴忚璁′腑鍗犵潃闈炲父閲嶈鐨勫湴浣嶃€傚鏋滄病鏈変腑鏂紝鍒機pu鐨勫伐浣滄晥鐜囦細澶ф姌鎵c€傚氨鍍忔垜浠殑uart妯″潡涓紝鎺ユ敹鐢佃剳鍙戦€佹潵鐨勬暟鎹紝浣跨敤浜唚hile(鏌ヨ鏍囧織)(鏌ヨ鐘舵€佺殑鏂瑰紡锛屽鏋滅數鑴戞病鏈夊彂閫佹暟鎹紝鍒欑▼搴忎細涓€鐩撮樆濉烇紝浣緾pu鍋氫笉浜嗗叾浠栦簨鎯呫€傚鏋滄湁涓€绉嶆満鍒讹紝涓嶇敤cpu寰幆鏌ヨ鏄惁鏈夋暟鎹埌鏉ワ紝鑰屾槸纭欢鑷姩鎺ユ敹鏁版嵁锛屽綋鏀跺埌鏁版嵁鏃跺€欑殑鑷姩閫氱煡cpu锛岃繖鏃跺€機pu鍐嶅幓鎶婃暟鎹鍙栧嚭鏉ャ€傝繖鏍凤紝鍦ㄦ病鏈夋暟鎹帴鏀跺埌鍓嶏紝cpu鍙互鍘诲仛鍏朵粬浜嬫儏锛屽伐浣滄晥鐜囪嚜鐒跺氨鎻愰珮浜嗐€傚湪cpu 纭欢涓紝閫氳繃涓柇杩欑鏈哄埗鏉ュ疄鐜拌繖涓姛鑳斤紝姣忎釜鐗囦笂澶栬纭欢閮芥彁渚涗竴涓腑鏂俊鍙凤紝褰撴ā鍧楀鐞嗙壒瀹氬伐浣滅姸鎬佹椂锛屼細鍙戝嚭涓柇淇″彿閫氫俊cpu銆?/p>

3.2 stm32鐨勪腑鏂?/p>

3.2.1 stm32涓柇鐨勭壒鎬?/p>

cortex-m4鍐呴儴鍖呭惈鏈夊祵濂楀悜閲忎腑鏂帶鍒跺櫒涓庡唴鏍哥揣瀵嗚仈绯荤殑涓柇鎺у埗鍣?鍙敮鎸佷綆涓柇寤舵椂鍙绯荤粺寮傚父鍜屽璁句腑鏂繘琛屾帶鍒?/p>

16涓彲缂栫▼鐨勪紭鍏堢瓑绾?浣跨敤浜?浣嶄腑鏂紭鍏堢骇) 82涓彲灞忚棌涓柇閫氶亾:鍙噸瀹氫綅鐨勫悜閲忚〃

涓嶅彲灞忚斀涓柇杞欢涓柇鍔熻兘

聽 宓屽鍚戦噺涓柇鎺у埗鍣紙nic锛夋槸cortex-m4 鐨勪竴涓唴閮ㄥ櫒浠躲€備笌cpu绱у瘑缁撳悎锛岄檷浣庝腑鏂欢鏃讹紝璁╂柊杩涗腑鏂彲浠ュ緱鍒伴珮鏁堝鐞嗐€?聽 cortes-m3鏍稿績鐨勪腑鏂疄鐜版槸閫氳繃宓屽叆涓€涓狽vic鎺у埗鍣紝璇ユ帶鍒跺櫒鍔熻兘闈炲父寮哄ぇ銆傚湪涓柇澶勭悊涓婃晥鐜囧緢楂橈紝浼樺厛绾ч厤缃篃寰堢伒娲伙紱

3.2.2 nvic鎺у埗鍣ㄧ殑浼樺厛绾ц〃绀?/p>

nvic鎺у埗鍣ㄧ殑浼樺厛绾т娇鐢?涓簩杩涘埗浣嶈〃绀猴紝鍒嗘垚涓ら儴鍒嗚繘琛岃〃绀猴紝鍒嗗埆鏄姠鍗犱紭鍏堢骇浠ュ強鍝嶅簲浼樺厛绾с€?/p>

鎶㈠崰浼樺厛绾э細鍚箟鏄湪涓嶅悓鐨勭瓑绾т箣闂寸殑涓柇鍙互鐩镐簰宓屽锛岄珮浼樺厛绾у彲浠ヤ腑鏂綆浼樺厛绾э紝鏁板瓧灏忕殑浼樺厛绾ч珮锛涘搷搴斾紭鍏堢骇锛氬惈涔夋槸涓嶅悓鐨勫搷搴斾紭鍏堢骇鐨勪腑鏂笉鍙互鐩镐簰宓屽锛屼絾鏄綋鍝嶅簲浼樺厛绾х浉鍚岀殑鏃跺€欙紝鍝嶅簲浼樺厛绾т笉鍚岋紝澶氫釜涓柇婧愬悓鏃跺彂鐢熶腑鏂殑鏃跺€欙紝鍝嶅簲浼樺厛绾ч珮鐨勪腑鏂簨浠跺彲浠ヤ紭鍏堝搷搴旓紝鏁板瓧灏忕殑鍝嶅簲鐨勪紭鍏堢骇瓒婇珮銆傝嚜鐒朵紭鍏堢骇锛氬氨鏄垜浠殑nvic鎺у埗鍣ㄧ殑涓柇婧愮紪鍙凤紝鏁板瓧灏忕殑浼樺厛绾ч珮銆備綔鐢ㄦ槸锛氬綋鎶㈠崰浼樺厛绾у拰鍝嶅簲浼樺厛绾х浉鍚屼笖閮藉彂鐢熶簡涓柇鐨勬椂鍊欙紝鑷劧浼樺厛绾ч珮鐨勪紭鍏堝搷搴旓紝鏁板瓧灏忕殑浼樺厛绾ч珮銆?/p>

浼樺厛绾х瓑绾у皬缁擄細鎶㈠崰浼樺厛绾?鍝嶅簲浼樺厛绾?鑷劧浼樺厛绾э紝鎶㈠崰浼樺厛绾у喅瀹氫簡鏄惁鍙互宓屽锛屽搷搴斾紭鍏堢骇鍜岃嚜鐒朵紭鍏堢骇鍐冲畾鍙戠敓鐨勬椂鍊欙紝鍏堝搷搴斿摢涓€涓紙濡傛灉鎶㈠崰鐩稿悓锛屽氨姣旇緝鎴戜滑鐨勫搷搴斾紭鍏堢骇锛屼袱涓兘鐩稿悓鐨勮瘽锛岄偅灏辨瘮杈冩垜浠殑鑷劧浼樺厛绾э紝鑷劧浼樺厛绾ф槸鎴戜滑鍘傚鐢熶骇鍑烘潵鐨勬椂鍊欏凡缁忓喅瀹氬ソ鐨勪簡锛侊級

聽 stm32f10x鎶婃寚瀹氱殑涓柇浼樺厛绾х殑瀵勫瓨鍣ㄤ綅鐢ㄤ簡4涓綅锛岃繖鍥涗釜瀵勫瓨鍣ㄤ綅鐨勫垎缁勬柟寮忓彲浠ュ涓嬶細

缁勭紪鍙?prigroup鍖哄煙锛?浣嶏級 aircr[10:8]0xe000_ed0c 鎶㈠崰浼樺厛绾т綅鏁板搷搴斾紭鍏堢骇浣嶆暟鎶㈠崰浼樺厛绾у彲閰嶇疆鑼冨洿鍝嶅簲浼樺厛绾у彲閰嶇疆鑼冨洿00x070400-1510x06130-10-720x05220-30-330x04310-70-140x03410-150

瑕侀厤缃垎缁勭殑璇濓紝鎸夌収涓婇潰鐨勮繖涓〃鏍硷紝瑕佸皢prigroup鍒楃殑鍊煎啓鍒版垜浠殑aircr[10:8]褰撲腑锛屼竴涓▼搴忓彧鏈変竴涓垎缁勶紝褰撳垎缁勭‘瀹氱殑鏃跺€欙紝閭d釜鍏朵腑鐨勫搷搴斾紭鍏堢骇鍜屾姠鍗犱紭鍏堢骇涔熷氨纭畾浜嗭紒

3.3 涓柇鍚戦噺琛?聽

浣嶇疆浼樺厛绾у悕绉拌鏄庡湴鍧€07wwdg绐楀彛瀹氭椂鍣ㄤ腑鏂?x0000_004018pvd杩炴帴鍊扙xti鐨勭數婧愮數鍘嬫娴嬩腑鏂?x0000_004429tamper娓呭剴妫€娴嬩腑鏂?x0000聽 0048310rtc瀹炴椂鏃堕挓鍏ㄥ眬涓柇0x0000聽 004c411flash闂瓨鍏ㄥ眬涓柇0x0000聽 0050512rcc澶嶄綅鍜屾椂閽熸帶鍒朵腑鏂?x0000聽 0054613exti0exti绾?涓柇0x0000聽 0058714exti1exti绾?涓柇0x0000聽 005c815exti2exti绾?涓柇0x0000聽 0060916exti3exti绾?涓柇0x0000聽 00641017exti4exti绾?涓柇0x0000聽 00681118dma閫氶亾1dma閫氶亾1鍏ㄥ眬涓柇0x0000聽 006c1219dma閫氶亾2dma閫氶亾2鍏ㄥ眬涓柇0x0000聽 00701320dma閫氶亾3dma閫氶亾3鍏ㄥ眬涓柇0x0000聽 00741421dma閫氶亾4dma閫氶亾4鍏ㄥ眬涓柇0x0000聽 00781522dma閫氶亾5dma閫氶亾5鍏ㄥ眬涓柇0x0000聽 007c1623dma閫氶亾6dma閫氶亾6鍏ㄥ眬涓柇0x0000聽 00801724dma閫氶亾7dma閫氶亾7鍏ㄥ眬涓柇0x0000聽 00841825adcadc1銆?銆?鐨勫叏灞€涓柇0x0000聽 00881926can1_txcan tx涓柇0x0000聽 008c2027can1_rx0can1_rx0涓柇0x0000聽 00902128can_rx1can_rx1涓柇0x0000聽 00942229can_scecan_sce涓柇0x0000聽 00982330exti9_5exti[9:5]涓柇0x0000聽 009c2431timi_brk_tim9timi鍒硅溅涓柇鍜孴im9鍏ㄥ眬涓柇0x0000聽 00a02532tim1_up_tim10timi鏇存柊涓柇鍜孴im9鍏ㄥ眬涓柇0x0000聽 00a42633tim1_cc鎹曡幏姣旇緝涓柇0x0000聽 00ac2734tim2tim2鍏ㄥ眬涓柇0x0000聽 00b02835tim3tim3鍏ㄥ眬涓柇0x0000聽 00b42936tim4tim4鍏ㄥ眬涓柇0x0000聽 00b8

3.4 stm32涓柇缂栫▼

鎴戜滑鐭ラ亾鐢变簬鎴戜滑鐨凬vic鏄竴涓睘浜庡唴鏍哥骇鍒殑澶栬锛屾垜浠墍鏈夌殑鍘傚鐨勮姱鐗囧湪瀵勫瓨鍣ㄤ笂闈㈤兘鏄竴鏍风殑锛屾墍浠ラ厤缃柟娉曚互鍙婇厤缃悗鐨勪綔鐢ㄩ兘鏄竴鏍风殑銆傛墍浠rm鍏徃宸茬粡缁欐垜浠彁渚涗簡涓€浠介€氱敤鐨凬vic鐨勯厤缃嚱鏁帮紝鎴戜滑鍙渶瑕佸紕娓呮浠栦滑鐨勪綔鐢ㄤ互鍙婁娇鐢ㄦ柟娉曞氨鍙互浜嗭紒

3.4.1 nvic鍒嗙粍璁剧疆聽

voidnvic_setpriorutygrouping(uint32_tprioritygroup)锛?/p>

prioritygroup锛氬垎缁勬柟寮忓搴旂殑鍊硷紝0-7缁勬垜浠墠闈㈠凡缁忚浜嗭紝绠€鍗曠殑渚嬪瓙灏辨槸姣斿浣犻€夋嫨鐨勬槸绗簩缁勶紝閭d箞灏辨槸2浣嶇殑鎶㈠崰浼樺厛绾э紝閭d箞瀵瑰簲鐨勫€煎氨鏄?-2=5锛涙垜浠缃垎缁?鐨勬柟寮忥紝

nvic_setpriorutygrouping(7-2)锛汚ircr[10:8] .

3.4.2 nvic浼樺厛绾х紪鐮?/p>

uint32_t nvic_encodepriority(uint32_tpriorutygroup,uint32_tpreemppriority,uint32_tsubpriority);

鎴戜滑杩欎釜鍑芥暟鎶婂垎缁勬柟寮忥紝鎶㈠崰浼樺厛绾э紝瀛愪紭鍏堢骇鏁板€肩紪鐮佹垚涓€涓?2浣嶇殑鏁板瓧锛屼綔涓烘垜浠殑杩斿洖鍊艰繑鍥炪€?/p>

priorutygroup锛氬垎缁勬柟寮忓搴旂殑鍊硷紝涔熷氨鏄疉ircr[10:8]涓殑鍊硷紝鎴栬€呬篃鍙互璇存槸nvic_setprioritygrouuping鍑芥暟鐨勫弬鏁般€?/p>

preemptpriority:姝g‘鐨勬姠鍗犱紭鍏堢骇鍊硷紝姣斿鍒嗙粍2锛岃寖鍥存槸0~3鍙栧€硷紝subpriority:姝g‘鐨勫瓙浼樺厛绾у€?姣斿鍒嗙粍2锛岃寖鍥存槸0~3鍙栧€硷紝 璇存槑:杩欎釜鍑芥暟骞舵病鏈夋妸浼樺厛绾ц缃埌瀵勫瓨鍣ㄤ腑锛屽彧鏄畝鍗曠殑鍚堟垚涓€涓〃绀轰紭鍏堢骇鏁板瓧銆傚悗闈㈠啀浣跨敤鍏朵粬鏁拌缃繖涓€煎埌瀵勫瓨鍣ㄤ腑銆?鍙互浣跨敤绉讳綅鏂瑰紡閰嶇疆浼樺厛绾с€備絾鏄厤缃笂姣旇緝楹荤儲銆?pri=nwic_encodepriority(7-2锛?锛?);鈫掑垎缁?锛屾姠鍗犱紭鍏堢骇鏄?锛屽搷搴斾紭鍏堢骇鏄?銆傝繑鍥炵紪鐮佸悗鐨勫€?涓€煎氨鏄啓鍏ュ搴斾腑鏂簮涓柇瀵勫瓨鍣ㄤ腑鐨勫€笺€傝繖涓嚱鏁板苟娌℃湁鍐欏叆瀵勫瓨鍣ㄤ腑銆?/p>

3.4.3 nvic浼樺厛绾ч厤缃?/p>

void nvic_setpriority(lrqn_typeirqn,uint32_tpriority)璇ュ嚱鏁扮敤浜庤缃寚瀹氫腑鏂簮鐨勪腑鏂紭鍏堢骇銆?irqn_type鏄湪 stm32f10x.h鏂囦欢涓湁瀹氫箟,涓€涓灇涓剧被鍨?瀹氫箟浜哠tm32f10x鑺墖瀵瑰簲鎵€鏈夌殑涓柇婧愮紪寮旾rqn:涓柇婧愮紪鍙凤紱 priority:涓柇浼樺厛绾э紝灏辨槸浣跨敤nic_encodepriority()鍑芥暟缂栫爜鐨勮繑鍥炲€笺€侾ri=nvic_encodepriority(7-2锛?.3);聽 聽 //usart1__irqn=37, nvic_setpriority(usart1_irqn锛孭ri);聽 //璁剧疆涓插彛1鐨勪腑鏂紭鍏堢骇銆?/p>

3.4.4 nvic涓柇浣胯兘

涓柇浣胯兘涔熸槸鐢盢vic鎺у埗鍣ㄦ帶鍒剁殑銆?0xe000_e100 - 0xe000_e11c杩欎釜鍦板潃鑼冨洿鐨勫瀛樺櫒鏄敤鏉ラ厤缃腑鏂娇鑳姐€備竴涓腑鏂簮鍙涓€涓綅銆?涓€涓瘎瀛樺櫒鏄?2浣嶃€傛€诲叡鏈?涓瘎瀛樺櫒锛屼綅鏁版槸32*8=256. 涓嬪浘鏈€鍚庝竴涓瘎瀛樺櫒setena7绠?24~239鍙蜂腑鏂€傚叡15 1=16涓腑鏂€傚墠闈㈢殑閮芥槸绠?2涓€?鍘熷洜鏄疭etena0~setena7鍙兘鐢ㄤ簬浣胯兘鍘傚鐨勫鎵╃殑涓柇婧愩€備笉鐢ㄤ簬绠$悊cortex-m3鏍稿績鍗犵敤鐨勫墠16涓腑鏂€?姣斿:stm32f103鐨刄sarti涓柇浣胯兘锛屽氨瑕侀厤缃甋etena1[3]浣嶄负l锛屽叾浠栦腑鏂被浼笺€倂oid nvic_enableirq(irqn_typeirqn) 璇ュ嚱鏁扮敤浜庝娇鑳芥寚瀹氫腑鏂簮銆?/浣胯兘涓插彛涓柇

3.4.5 鍒濆鍖朜vic鎺у埗鍣ㄧ殑姝ラ

1.璁剧疆鍒嗙粍鏂瑰紡 2锛庣‘瀹氫腑鏂簮鐨勬姠鍗犱紭鍏堢骇鍜屽搷搴斾紭鍏堢骇锛屼娇鐢∟vic_encodepriority鍑芥暟杩涜缂栫爜

3.鎶婁笂涓嬬紪鐮佸緱鍒颁紭鍏堢骇鍊煎啓鍏ヤ紭鍏堢骇閰嶇疆瀵勫瓨鍣紝浣跨敤nvic_setpriority鍑芥暟銆?/p>

4浣胯兘瀵瑰簲涓柇婧?浣跨敤nvic_enableirq鍑芥暟銆?5锛庡叿浣撶殑妯″潡涓柇:杩樿鍘婚厤缃璁句腑鏂浉鍏崇殑瀵勫瓨鍣紙涓嬪皬鑺備細浠ュ閮ㄤ腑鏂互渚嬪瓙璁茶в)

6.缂栧啓涓柇鏈嶅姟鍑芥暟: 1)鍒板惎鍔ㄤ唬鐮佷腑鎵惧埌瀵瑰簲鐨勪腑鏂叆鍙?浠ョ‘瀹氫腑鏂嚱鏁板悕瀛楋紱 2锛夊湪c鏂囦欢涓紪鍐欎竴涓棤杩斿洖鍊硷紝鏃犵被鍨嬬殑鍑芥暟銆傚嚱鏁板悕灏辨槸涓婁竴姝ュ緱鍒扮殑鍚嶅瓧銆?/p>

3.4.6 涓柇鏈嶅姟鍑芥暟缂栧啓 聽

姣斿鎴戜滑瑕佺紪鍐欎竴涓腑鏂湇鍔″嚱鏁扮殑璇濓紝鎴戜滑鐩存帴鍒颁綘宸ョ▼鐨勫惎鍔ㄦ枃浠跺氨鍙互灏嗚繖涓嚱鏁扮殑鍛藉悕澶嶅埗涓嬫潵锛屽崈涓囧埆鑷繁鎵嬪姩鏁诧紱

聽渚嬪鎴戜滑缂栧啓涓€涓狤xti绾?鐨勪腑鏂湇鍔″嚱鏁帮紱鎴戜滑鐩存帴鍒版垜浠殑鍚姩鏂囦欢鎵惧埌鎴戜滑鐨勭浉搴旂殑鍑芥暟鍚嶅鍒朵笅鏉ュ氨鍙互浜嗭細

聽鍑芥暟鐨勭紪鍐欐牸寮忓涓嬶細

void exti0_irqhandler(void) { 浣犳兂瑕佺紪鍐欏疄鐜扮殑鍐呭锛氾紙锛?/p>

}

鎴戜滑鍐欎竴涓腑鏂寜閿帶鍒剁伅鐨勶紝鎴戜滑灏卞彲浠ヨ繖鏍峰瓙鍐欙紱

void exti0_irqhandler(void)

{

exti_clearitpendingbit(exti_line0); //娓呴櫎澶栭儴涓柇0鏍囧織浣?/p>

led1= !led1;

}

聽娉ㄦ剰锛氳繖閲岃鏄庝竴涓嬶紝鎴戜滑鐨勪腑鏂湇鍔″嚱鏁板湪缂栧啓鍐呭涓婇潰鍜屾垜浠殑鏅€氫唬鐮佹病鏈変粈涔堝お澶х殑鍖哄埆锛屽ぇ瀹跺彲浠ユ牴鎹嚜宸辩殑闇€瑕佺紪鍐欏姛鑳戒唬鐮侊紝鍙湁閲岄潰涓€瀹氳鏈夋竻闄や腑鏂爣蹇椾綅鐨勪唬鐮佸氨鍙互浜嗐€備腑鏂湇鍔″嚱鏁板悕瑕佸拰鎴戜滑鐨勫惎鍔ㄦ枃浠跺搴旂殑涓柇婧愮殑涓柇鍏ュ彛鏍囧織鐩稿悓銆傚苟涓旇繕鏄渶瑕佸師鍨嬩负voidfun锛坴oid锛?

4.uart鍜孶sart聽

4.1 uart绠€浠?/p>

聽 鎴戜滑鐨勪覆琛屾帴鍙f寚鐨勬槸鏁版嵁涓€浣嶄竴浣嶇殑椤哄簭浼犺緭浼犻€佽繃鍘伙紝瀹冪殑鐗圭偣灏辨槸閫氫俊鐨勭嚎璺畝鍗曪紝鍙鏈変竴瀵逛紶杈撶嚎灏卞彲浠ュ疄鐜板弻鍚戦€氫俊锛堝彲浠ョ洿鎺ュ埄鐢ㄧ數璇濈嚎浣滀负浼犺緭绾匡級锛屼粠鑰屽ぇ澶х殑闄嶄綆浜嗘垚鏈紝鐗瑰埆鏄湪鎴戜滑鐨勮繙璺濈閫氫俊锛屼絾鏄紶杈撶殑閫熷害寰堟參銆?/p>

聽 涓€鏉′俊鎭殑涓綅鏁版嵁琚€愪綅鎸夐『搴忎紶閫佺殑閫氳鏂瑰紡鎴愪负涓茶閫氳銆傝閫氳鐨勭壒鐐规槸锛氭暟鎹綅鐨勪紶閫佹槸鎸変綅杩涜鐨勶紝鏈€灏戝彧闇€瑕佷竴鏉℃暟鎹嚎灏卞彲浠ュ畬鎴愶紱鎴愭湰姣旇緝浣庝絾鏄€熷害寰堟參銆備覆琛岄€氳鐨勮窛绂讳竴鑸彲浠ヤ粠鏈哄瘑鍒板嚑鍗冪背锛涙垜浠牴鎹暟鎹殑浼犺緭鏂瑰悜锛屼覆琛岄€氳鍙互鍒嗘垚涓夌--鍗曞伐銆佸崐鍙屽伐銆佸叏鍙屽伐锛?/p>

鍗曞伐锛氬彧鏈変竴涓柟鍚戠殑鏁版嵁浼犺緭锛涘崐鍙屽伐锛氭暟鎹彲浠ュ湪涓€涓俊鍙风殑杞戒綋涓婄殑涓や釜鏂瑰悜浼犺緭锛屼笉鏄笉鍙互杩涜鍒板悓鏃剁殑浼犺緭锛屾暟鎹嚎鍒嗕负澶嶇敤锛涘叏鍙屽伐锛氬弻鍚戠殑鏁版嵁浼犺緭锛涘厑璁告暟鎹湪涓や釜鏂瑰悜涓婇潰鐨勫悓鏃朵紶杈擄紝浠栧湪鑳藉姏涓婄浉褰撲簬涓や釜浣嗘柦宸ョ殑缁撳悎銆?/p>

聽閲嶇偣鏉ヤ簡锛?/p>

uart锛坲niversal asynchronous receiver transmitter锛夛紝鎴戜滑鎸囩殑鏄紓姝ヤ覆琛岋紝universal asynchronous receiver transmitter锛堥€氱敤寮傛鎺ユ敹鍙戦€侊級銆傚湪杩欓噷uart鏄竴涓苟琛岃緭鍏ユ垚涓轰覆琛岃緭鍏ョ殑鑺墖锛岄€氬父浼氶泦鎴愬湪鎴戜滑鐨勬澘杞戒笂闈€?/p>

聽 uart鍖呭惈tlt鐢靛钩锛堢數骞充负3.3v锛夌殑涓插彛鍜孯s232鐢靛钩锛堣礋閫昏緫鐢靛钩锛?5-12v浣庣數骞筹紱-12-5浣嶉珮鐢靛钩锛夌殑涓插彛銆?/p>

4.2 usart

聽 閫氱敤鍚屾寮傛鎺ュ彈鍙戦€佹帶鍒跺櫒锛屾槸涓€濂楁彁渚涗簡鐏垫椿鐨勬柟娉曚笌浣跨敤宸ヤ笟鏍囧噯nrz寮傛鍒涙柊鏁版嵁鏍煎紡鐨勫閮ㄨ澶囦箣闂磋繘琛屽叏鍙屽伐鏁版嵁浜ゆ崲銆俇sart鍒╃敤鍒嗘暟涓插垪浼犺緭閫熺巼鍙戠敓鍣ㄦ彁渚涘鑼冨洿鐨勪覆鍒椾紶杈撻€熺巼閫夋嫨銆傚畠鏀寔鍚屾鍗曠嚎閫氫俊鍜屽崐鍙屽伐鍗曠嚎閫氫俊锛屼篃鏀寔灞€閮ㄨ仈缃戯紝鏅鸿兘鍗″崗璁拰绾㈠鏁版嵁缁勭粐浠ュ強璋冨埗瑙h皟鍣ㄦ搷浣滐紝杩樺厑璁稿涓鐞嗗櫒閫氫俊銆備娇鐢ㄥ缂撳啿鍣ㄩ厤缃殑dma鏂瑰紡锛屽彲浠ュ疄鐜伴珮閫熸暟鎹€氫俊銆?/p>

聽 鎴戜滑鎺ュ彛閫氳繃鐨勬槸涓変釜寮曡剼鍜屽叾浠栫殑璁惧閾炬帴鍒颁竴璧凤紝浠讳綍鐨刄sart鍙屽悜閫氫俊鑷冲皯閮借涓や釜寮曡剼锛氭帴鏀舵暟鎹緭鍏ワ紙rx锛夊拰鍙戦€佹暟鎹緭鍑猴紙tx锛夛紱

rx锛氭帴鏀舵暟鎹緭鍏ャ€傞€氳繃閲囨牱鎶€鏈潵鍖哄埆鏁版嵁鍜屽櫔闊筹紝浠庤€屾仮澶嶆暟鎹紱

tx锛氬彂閫佹暟鎹緭鍑恒€傚綋鍙戦€佸櫒琚姝㈢殑鏃跺€欙紝杈撳嚭寮曡剼鎭㈠鍒板畠鐨処/o绔彛閰嶇疆銆傚綋鍙戦€佸櫒婵€娲荤殑鏃跺€欙紝骞朵笖涓嶅彂閫佹暟鎹殑鏃跺€欙紝tx寮曡剼澶勪簬楂樼數骞炽€?/p>

鎬荤嚎鍦ㄥ彂閫佹垨鑰呮帴鏀跺墠澶勪簬绌洪棽鐘舵€侊紱涓€涓捣濮嬩綅锛涗竴涓?鎴?浣嶇殑涔﹀眬瀛楋紝鏈€浣庢湁鏁堜綅鍦ㄥ墠锛?.5銆?.5銆?涓仠姝綅锛岀敱姝よ〃鏄庢暟鎹抚缁撴潫锛涗娇鐢ㄥ垎鏁版尝鐗圭巼鍙戠敓鍣?-12浣嶆暣鏁板拰4浣嶅皬鏁帮紱涓€涓姸鎬佸瘎瀛樺櫒锛圲sart_sr锛夛紱鏁版嵁瀵勫瓨鍣紙usart_dr锛夛紱涓€涓尝鐗圭巼瀵勫瓨鍣紙usart_brr锛夛紝12浣嶆暣鏁板拰4浣嶅皬鏁帮紱涓€涓櫤鑳藉崱妯″紡涓嬬殑淇濇姢鏃堕棿瀵勫瓨鍣紙usart_gtpr锛夈€?/p>

4.3 uart鐗规€?/p>

瀛楄妭鍙互閫氳繃缂栫▼usart鈥斺€擟r1瀵勫瓨鍣ㄤ腑鐨凪浣嶏紝閫夋嫨鎴?鎴栬€?浣嶃€傚湪鍏跺疄鏈熼棿锛孴x鑴氬浜庝綆鐢靛钩锛屽湪鍋滄浣嶆湡闂村浜庨珮鐢靛钩锛涚┖闂茬鍙疯瑙嗕负瀹屽叏鏈夆€?鈥欑粍鎴愮殑涓€涓畬鏁寸殑鏁版嵁甯э紝鍚庨潰璺熺潃鍖呭惈鐨勪笅涓€涓抚鐑︿汉寮€濮嬩负锛堚€?鈥欑殑浣嶆暟涔熷寘鎷簡瀹氬埗涓虹殑浣嶆暟锛夛紱鏂紑绗﹀彿聽 琚涓哄湪涓€涓抚鍛ㄦ湡鍏ㄩ儴鏀跺埌鈥?鈥濆寘鎷仠姝綅锛屼篃鏄€?鈥濄€傚湪鏂紑甯х粨鏉熺殑鏃跺€欙紝鍙戦€佸櫒鍐嶆彃鍏?鎴?涓仠姝綅锛堚€?鈥欙級鏉ュ簲绛旇捣濮嬩綅锛涘湪鏂紑甯х粨鏉熸椂锛屽彂閫佸櫒鍐嶆彃鍏?鎴?鍋滄浣嶏紙鈥?鈥欙級鏉ュ簲绛旇捣濮嬩綅锛涘彂閫佸拰鎺ユ敹鐢变竴涓敤鐨勬尝鐗圭巼鍙戠敓鍣ㄩ┍鍔紝褰撳彂閫佸櫒鍜屾帴鏀跺櫒鐨勪娇鑳戒綅鍒嗗埆缃綅鐨勬椂鍊欙紝鍒嗗埆涓哄叾浜х敓鏃堕挓銆?/p>

聽4.4 涓插彛濡備綍宸ヤ綔

涓插彛鐨勫伐浣滄湁涓ょ鏂瑰紡锛氭煡璇㈠拰涓柇锛?/p>

鏌ヨ锛氫覆鍙g▼搴忎笉鏂殑寰幆鏌ヨ锛屾煡鐪嬪綋鍓嶆湁娌℃湁鏁版嵁瑕佷粬浼犻€侊紝鏈夌殑璇濓紝灏卞府瀹冧紶閫侊紙鍙互浠嶱c绔埌stm32鏉垮瓙浼犻€侊紝涔熷彲浠ヤ粠stm32鏉垮瓙鍒癙c绔級锛?/p>

涓柇:褰撲覆鍙f墦寮€涓柇鏃讹紝濡傛灉鍙戠幇鏈変竴涓暟鎹埌鏉ユ垨鏁版嵁鍙戦€佸畬姣曪紝鍒欎細鍙戠敓涓柇锛屽氨浠ヤ负鐫€瀹冨府鍔╀紶杈撴暟鎹?-瀹冨氨椹笂杩涜鏁版嵁鐨勪紶閫併€傚悓鏃讹紝鍙互浠嶱c鏈哄埌stm32f4鏉垮瓙锛屼篃鍙互浠嶴tm32f4鏉垮瓙鍒癙c绔紒

瀛楄妭璁剧疆

閰嶇疆鍋滄浣?

聽娉㈢壒鐜囩殑浜х敓

鎺ユ敹鍣ㄥ拰鍙戦€佸櫒鐨勬尝鐗圭巼鍦║asrtdiv鐨勬暣鏁板拰灏忔暟瀵勫瓨鍣ㄤ腑鐨勫€煎簲璁剧疆鎴愮浉鍚屻€傝繖閲岀殑fck鏄粰澶栬鐨勬椂閽燂紙pclk1鐢ㄤ簬usart2銆?銆?銆?锛孭clk2鐢ㄤ簬usart1锛夈€俇sartdiv鏄竴涓棤绗﹀彿鐨勫畾鐐规暟銆傝繖12浣嶇殑鍊艰缃湪usart_brr瀵勫瓨鍣ㄣ€傛柟鍥惧涓嬶細

usart绯荤粺妗嗘灦鍥?

4.5 涓嶶art鐩稿叧鐨勫瘎瀛樺櫒

聽 聽4.5.1 鐘舵€佸瘎瀛樺櫒锛圲sart_sr锛壜?/p>

浣?9 cts锛欳ts 鏍囧織 (cts flag)

聽 濡傛灉 ctse 浣嶇疆 1锛屽綋 ncts 杈撳叆鍙樻崲鏃讹紝姝や綅鐢辩‖浠剁疆 1銆傞€氳繃杞欢灏嗚浣嶆竻闆讹紙閫氳繃鍚?/p>

璇ヤ綅涓啓鍏?0锛夈€傚鏋?usart_cr3 瀵勫瓨鍣ㄤ腑 ctsie=1锛屽垯浼氱敓鎴愪腑鏂€?/p>

0锛歯cts 鐘舵€佺嚎涓婃湭鍙戠敓鍙樺寲

1锛歯cts 鐘舵€佺嚎涓婂彂鐢熷彉鍖?/p>

娉ㄦ剰锛氳浣嶄笉閫傜敤浜?uart4 鍜?uart5銆?/p>

浣?8 lbd锛歀in 鏂矾妫€娴嬫爣蹇?(lin break detection flag)

妫€娴嬪埌 lin 鏂矾鏃讹紝璇ヤ綅鐢辩‖浠剁疆 1銆傞€氳繃杞欢灏嗚浣嶆竻闆讹紙閫氳繃鍚戣浣嶄腑鍐欏叆 0锛夈€傚鏋?/p>

usart_cr2 瀵勫瓨鍣ㄤ腑 lbdie = 1锛屽垯浼氱敓鎴愪腑鏂€?/p>

0锛氭湭妫€娴嬪埌 lin 鏂矾

1锛氭娴嬪埌 lin 鏂矾

娉ㄦ剰锛氬鏋?lbdie=1锛屽垯褰?lbd=1 鏃剁敓鎴愪腑鏂?

浣?7 txe锛氬彂閫佹暟鎹瘎瀛樺櫒涓虹┖ (transmit data register empty)

褰?tdr 瀵勫瓨鍣ㄧ殑鍐呭宸蹭紶杈撳埌绉讳綅瀵勫瓨鍣ㄦ椂锛岃浣嶇敱纭欢缃?1銆傚鏋?usart_cr1 瀵勫瓨鍣?/p>

涓?txeie 浣?= 1锛屽垯浼氱敓鎴愪腑鏂€傞€氳繃瀵?usart_dr 瀵勫瓨鍣ㄦ墽琛屽啓鍏ユ搷浣滃皢璇ヤ綅娓呴浂銆?/p>

0锛氭暟鎹湭浼犺緭鍒扮щ浣嶅瘎瀛樺櫒

1锛氭暟鎹紶杈撳埌绉讳綅瀵勫瓨鍣?/p>

娉ㄦ剰锛氬崟缂撳啿鍖哄彂閫佹湡闂翠娇鐢ㄨ浣?/p>

浣?6 tc锛氬彂閫佸畬鎴?(transmission complete)

濡傛灉宸插畬鎴愬鍖呭惈鏁版嵁鐨勫抚鐨勫彂閫佸苟涓?txe 缃?1锛屽垯璇ヤ綅鐢辩‖浠剁疆 1銆傚鏋?usart_cr1 瀵勫瓨

鍣ㄤ腑 tcie = 1锛屽垯浼氱敓鎴愪腑鏂€傝浣嶇敱杞欢搴忓垪娓呴浂锛堣鍙?usart_sr 瀵勫瓨鍣紝鐒跺悗鍐欏叆

usart_dr 瀵勫瓨鍣級銆俆c 浣嶄篃鍙互閫氳繃鍚戣浣嶅啓鍏モ€?/p>

0鈥欐潵娓呴浂銆傚缓璁粎鍦ㄥ缂撳啿鍖洪€氫俊

鏃朵娇鐢ㄦ娓呴浂搴忓垪銆?/p>

0锛氫紶閫佹湭瀹屾垚

1锛氫紶閫佸凡瀹屾垚

浣?5 rxne锛氳鍙栨暟鎹瘎瀛樺櫒涓嶄负绌?(read data register not empty)

褰?rdr 绉讳綅瀵勫瓨鍣ㄧ殑鍐呭宸蹭紶杈撳埌 usart_dr 瀵勫瓨鍣ㄦ椂锛岃浣嶇敱纭欢缃?1銆傚鏋?/p>

usart_cr1 瀵勫瓨鍣ㄤ腑 rxneie = 1锛屽垯浼氱敓鎴愪腑鏂€傞€氳繃瀵?usart_dr 瀵勫瓨鍣ㄦ墽琛岃鍏?/p>

鎿嶄綔灏嗚浣嶆竻闆躲€俁xne 鏍囧織涔熷彲浠ラ€氳繃鍚戣浣嶅啓鍏ラ浂鏉ユ竻闆躲€傚缓璁粎鍦ㄥ缂撳啿鍖洪€氫俊鏃朵娇

鐢ㄦ娓呴浂搴忓垪銆?/p>

0锛氭湭鎺ユ敹鍒版暟鎹?/p>

1锛氬凡鍑嗗濂借鍙栨帴鏀跺埌鐨勬暟鎹?/p>

浣?4 idle锛氭娴嬪埌绌洪棽绾胯矾 (idle line detected)

妫€娴嬪埌绌洪棽绾胯矾鏃讹紝璇ヤ綅鐢辩‖浠剁疆 1銆傚鏋?usart_cr1 瀵勫瓨鍣ㄤ腑 idleie = 1锛屽垯浼氱敓鎴愪腑

鏂€傝浣嶇敱杞欢搴忓垪娓呴浂锛堣鍏?usart_sr 瀵勫瓨鍣紝鐒跺悗璇诲叆 usart_dr 瀵勫瓨鍣級銆?/p>

0锛氭湭妫€娴嬪埌绌洪棽绾胯矾

1锛氭娴嬪埌绌洪棽绾胯矾

娉ㄦ剰锛氱洿鍒?rxne 浣嶆湰韬凡缃?1 鏃讹紙鍗筹紝褰撳嚭鐜版柊鐨勭┖闂茬嚎璺椂锛塈dle 浣嶆墠浼氳鍐嶆缃?1銆?

浣?3 ore锛氫笂婧㈤敊璇?(overrun error)

鍦?rxne = 1 鐨勬儏鍐典笅锛屽綋绉讳綅瀵勫瓨鍣ㄤ腑褰撳墠姝e湪鎺ユ敹鐨勫瓧鍑嗗濂戒紶杈撳埌 rdr 瀵勫瓨鍣ㄦ椂锛岃

浣嶇敱纭欢缃?1銆傚鏋?usart_cr1 瀵勫瓨鍣ㄤ腑 rxneie = 1锛屽垯浼氱敓鎴愪腑鏂€傝浣嶇敱杞欢搴忓垪娓?/p>

闆讹紙璇诲叆 usart_sr 瀵勫瓨鍣紝鐒跺悗璇诲叆 usart_dr 瀵勫瓨鍣級銆?/p>

0锛氭棤涓婃孩閿欒

1锛氭娴嬪埌涓婃孩閿欒

娉ㄦ剰锛氬綋璇ヤ綅缃?1 鏃讹紝rdr 瀵勫瓨鍣ㄧ殑鍐呭涓嶄細涓㈠け锛屼絾绉讳綅瀵勫瓨鍣ㄤ細琚鐩栥€傚鏋?eie 浣嶇疆 1锛?

鍒欏湪杩涜澶氱紦鍐插尯閫氫俊鏃朵細瀵?ore 鏍囧織鐢熸垚涓€涓腑鏂€?

浣?2 nf锛氭娴嬪埌鍣0鏍囧織 (noise detected flag)

褰撳湪鎺ユ敹鐨勫抚涓婃娴嬪埌鍣0鏃讹紝璇ヤ綅鐢辩‖浠剁疆 1銆傝浣嶇敱杞欢搴忓垪娓呴浂锛堣鍏?usart_sr 瀵?/p>

瀛樺櫒锛岀劧鍚庤鍏?usart_dr 瀵勫瓨鍣級銆?/p>

0锛氭湭妫€娴嬪埌鍣0

1锛氭娴嬪埌鍣0

娉ㄦ剰锛氬鏋?eie 浣嶇疆 1锛屽垯鍦ㄨ繘琛屽缂撳啿鍖洪€氫俊鏃讹紝璇ヤ綅涓嶄細鐢熸垚涓柇锛屽洜涓鸿浣嶅嚭鐜扮殑鏃堕棿涓?

鏈韩鐢熸垚涓柇鐨?rxne 浣嶅洜 nf 鏍囧織鑰岀敓鎴愮殑鏃堕棿鐩稿悓銆?

娉ㄦ剰锛氬綋绾胯矾鏃犲櫔澹版椂锛屽彲浠ラ€氳繃灏?onebit 浣嶇紪绋嬩负 1 鎻愰珮 usart 瀵瑰亸宸殑瀹瑰樊鏉ョ姝?/p>

浣?1 fe锛氬抚閿欒 (framing error)

褰撴娴嬪埌鍘诲悓姝ュ寲銆佽繃搴︾殑鍣0鎴栦腑鏂瓧绗︽椂锛岃浣嶇敱纭欢缃?1銆傝浣嶇敱杞欢搴忓垪娓呴浂锛堣鍏?/p>

usart_sr 瀵勫瓨鍣紝鐒跺悗璇诲叆 usart_dr 瀵勫瓨鍣級銆?/p>

0锛氭湭妫€娴嬪埌甯ч敊璇?/p>

1锛氭娴嬪埌甯ч敊璇垨涓柇瀛楃

娉ㄦ剰锛氳浣嶄笉浼氱敓鎴愪腑鏂紝鍥犱负璇ヤ綅鍑虹幇鐨勬椂闂翠笌鏈韩鐢熸垚涓柇鐨?rxne 浣嶅嚭鐜扮殑鏃堕棿鐩稿悓銆?

濡傛灉褰撳墠姝e湪浼犺緭鐨勫瓧鍚屾椂瀵艰嚧甯ч敊璇拰涓婃孩閿欒锛屽垯浼氫紶杈撹瀛楋紝涓斾粎鏈?ore 浣嶈

缃?1銆?

濡傛灉 eie 浣嶇疆 1锛屽垯鍦ㄨ繘琛屽缂撳啿鍖洪€氫俊鏃朵細瀵?fe 鏍囧織鐢熸垚涓€涓腑鏂€?

浣?0 pe锛氬鍋舵牎楠岄敊璇?(parity error)

褰撳湪鎺ユ敹鍣ㄦā寮忎笅鍙戠敓濂囧伓鏍¢獙閿欒鏃讹紝璇ヤ綅鐢辩‖浠剁疆 1銆傝浣嶇敱杞欢搴忓垪娓呴浂锛堣鍙栫姸鎬?/p>

瀵勫瓨鍣紝鐒跺悗瀵?usart_dr 鏁版嵁瀵勫瓨鍣ㄦ墽琛岃鎴栧啓璁块棶锛夈€傚皢 pe 浣嶆竻闆跺墠杞欢蹇呴』绛夊緟

rxne 鏍囧織琚疆 1銆?/p>

濡傛灉 usart_cr1 瀵勫瓨鍣ㄤ腑 peie = 1锛屽垯浼氱敓鎴愪腑鏂€?/p>

0锛氭棤濂囧伓鏍¢獙閿欒

1锛氬鍋舵牎楠岄敊璇?/p>

4.5.2 鏁版嵁瀵勫瓨鍣紙usart_dr锛?/p>

聽 聽

聽浣?8:0 dr[8:0]锛氭暟鎹€?/p>

鍖呭惈鎺ユ敹鍒版暟鎹瓧绗︽垨宸插彂閫佺殑鏁版嵁瀛楃锛屽叿浣撳彇鍐充簬鎵€鎵ц鐨勬搷浣滄槸鈥滆鍙栤€濇搷浣滆繕鏄?/p>

鈥滃啓鍏モ€濇搷浣溿€?/p>

鍥犱负鏁版嵁瀵勫瓨鍣ㄥ寘鍚袱涓瘎瀛樺櫒锛屼竴涓敤浜庡彂閫?(tdr)锛屼竴涓敤浜庢帴鏀?(rdr)锛屽洜姝ゅ畠鍏锋湁

鍙岄噸鍔熻兘锛堣鍜屽啓锛夈€?/p>

tdr 瀵勫瓨鍣ㄥ湪鍐呴儴鎬荤嚎鍜岃緭鍑虹щ浣嶅瘎瀛樺櫒涔嬮棿鎻愪緵浜嗗苟琛屾帴鍙o紙鍙傝鍥?1锛夈€?/p>

rdr 瀵勫瓨鍣ㄥ湪杈撳叆绉讳綅瀵勫瓨鍣ㄥ拰鍐呴儴鎬荤嚎涔嬮棿鎻愪緵浜嗗苟琛屾帴鍙c€?/p>

鍦ㄤ娇鑳藉鍋舵牎楠屼綅鐨勬儏鍐典笅锛圲sart_cr1 瀵勫瓨鍣ㄤ腑鐨?pce 浣嶈缃?1锛夎繘琛屽彂閫佹椂锛岀敱浜?/p>

msb 鐨勫啓鍏ュ€硷紙浣?7 鎴栦綅 8锛屽叿浣撳彇鍐充簬鏁版嵁闀垮害锛変細琚鍋舵牎楠屼綅鎵€鍙栦唬锛屽洜姝よ鍊间笉

璧蜂换浣曚綔鐢ㄣ€?/p>

鍦ㄤ娇鑳藉鍋舵牎楠屼綅鐨勬儏鍐典笅杩涜鎺ユ敹鏃讹紝浠?msb 浣嶄腑璇诲彇鐨勫€间负鎺ユ敹鍒扮殑濂囧伓鏍¢獙浣嶃€?/p>

4.5.3 娉㈢壒鐜囧瘎瀛樺櫒锛圲sart_brr锛壜?/p>

聽浣?31:16 淇濈暀锛屽繀椤讳繚鎸佸浣嶅€?锛涗綅 15:4 div_mantissa[11:0]锛歎sartdiv 鐨勫熬鏁?/p>

杩?12 涓綅鐢ㄤ簬瀹氫箟 usart 闄ゆ暟 (usartdiv) 鐨勫熬鏁?/p>

浣?3:0 div_fraction[3:0]锛歎sartdiv 鐨勫皬鏁帮紱

杩?4 涓綅鐢ㄤ簬瀹氫箟 usart 闄ゆ暟 (usartdiv) 鐨勫皬鏁般€傚綋 over8 = 1 鏃讹紝涓嶈€冭檻 div_fraction3

浣嶏紝涓斿繀椤诲皢璇ヤ綅淇濇寔娓呴浂銆?/p>

4.5.4 鎺у埗瀵勫瓨鍣紙usart_cr1锛?/p>

聽浣?31:16 淇濈暀锛屽繀椤讳繚鎸佸浣嶅€?/p>

浣?15 over8锛氳繃閲囨牱妯″紡 (oversampling mode)

0锛?6 鍊嶈繃閲囨牱

1锛? 鍊嶈繃閲囨牱

娉ㄦ剰锛? 鍊嶈繃閲囨牱鍦ㄦ櫤鑳藉崱銆両rda 鍜?lin 妯″紡涓嬩笉鍙敤锛氬綋 scen=1銆両ren=1 鎴?linen=1 鏃讹紝

over8 鐢辩‖浠跺己鍒舵竻闆躲€?

浣?14 淇濈暀锛屽繀椤讳繚鎸佸浣嶅€?/p>

浣?13 ue锛歎sart 浣胯兘 (usart enable)

璇ヤ綅娓呴浂鍚庯紝usart 棰勫垎棰戝櫒鍜岃緭鍑哄皢鍋滄锛屽苟浼氱粨鏉熷綋鍓嶅瓧鑺備紶杈撲互闄嶄綆鍔熻€椼€傛浣嶇敱杞?/p>

浠剁疆 1 鍜屾竻闆躲€?/p>

0锛氱姝?usart 棰勫垎棰戝櫒鍜岃緭鍑?/p>

1锛氫娇鑳?usart

浣?12 m锛氬瓧闀?(word length)

璇ヤ綅鍐冲畾浜嗗瓧闀裤€傝浣嶇敱杞欢缃?1 鎴栨竻闆躲€?/p>

0锛? 璧峰浣嶏紝8 鏁版嵁浣嶏紝n 鍋滄浣?/p>

1锛? 璧峰浣嶏紝9 鏁版嵁浣嶏紝n 鍋滄浣?/p>

娉ㄦ剰锛氬湪鏁版嵁浼犺緭锛堝彂閫佸拰鎺ユ敹锛夋湡闂翠笉寰楁洿鏀?m 浣?

浣?11 wake锛氬敜閱掓柟娉?(wakeup method)

璇ヤ綅鍐冲畾浜?usart 鍞ら啋鏂规硶锛岃浣嶇敱杞欢缃?1 鎴栨竻闆躲€?/p>

0锛氱┖闂茬嚎璺?/p>

1锛氬湴鍧€鏍囪

浣?10 pce锛氬鍋舵牎楠屾帶鍒朵娇鑳?(parity control enable)

璇ヤ綅閫夋嫨纭欢濂囧伓鏍¢獙鎺у埗锛堢敓鎴愬拰妫€娴嬶級銆備娇鑳藉鍋舵牎楠屾帶鍒舵椂锛岃绠楀嚭鐨勫鍋舵牎楠屼綅琚?/p>

鎻掑叆鍒?msb 浣嶇疆锛堝鏋?m=1锛屽垯涓虹 9 浣嶏紱濡傛灉 m=0锛屽垯涓虹 8 浣嶏級锛屽苟瀵规帴鏀跺埌鐨勬暟鎹?/p>

妫€鏌ュ鍋舵牎楠屼綅銆傛浣嶇敱杞欢缃?1 鍜屾竻闆躲€備竴鏃﹁浣嶇疆 1锛孭ce 鍦ㄥ綋鍓嶅瓧鑺傜殑鍚庨潰澶勪簬娲诲姩

鐘舵€侊紙鍦ㄦ帴鏀跺拰鍙戦€佹椂锛夈€?/p>

0锛氱姝㈠鍋舵牎楠屾帶鍒?/p>

1锛氫娇鑳藉鍋舵牎楠屾帶鍒?/p>

浣?9 ps锛氬鍋舵牎楠岄€夋嫨 (parity selection)

璇ヤ綅鐢ㄤ簬鍦ㄤ娇鑳藉鍋舵牎楠岀敓鎴?妫€娴嬶紙pce 浣嶇疆 1锛夋椂閫夋嫨濂囨牎楠屾垨鍋舵牎楠屻€傝浣嶇敱杞欢缃?1 鍜?/p>

娓呴浂銆傚皢鍦ㄥ綋鍓嶅瓧鑺傜殑鍚庨潰閫夋嫨濂囧伓鏍¢獙銆?/p>

0锛氬伓鏍¢獙

1锛氬鏍¢獙

浣?8 peie锛歅e 涓柇浣胯兘 (pe interrupt enable)

姝や綅鐢辫蒋浠剁疆 1 鍜屾竻闆躲€?/p>

0锛氱姝腑鏂?/p>

1锛氬綋 usart_sr 瀵勫瓨鍣ㄤ腑 pe=1 鏃讹紝鐢熸垚 usart 涓柇

浣?7 txeie锛歍xe 涓柇浣胯兘 (txe interrupt enable)

姝や綅鐢辫蒋浠剁疆 1 鍜屾竻闆躲€?/p>

0锛氱姝腑鏂?/p>

1锛氬綋 usart_sr 瀵勫瓨鍣ㄤ腑 txe=1 鏃讹紝鐢熸垚 usart 涓柇銆?/p>

浣?6 tcie锛氫紶閫佸畬鎴愪腑鏂娇鑳?(transmission complete interrupt enable)

姝や綅鐢辫蒋浠剁疆 1 鍜屾竻闆躲€?/p>

0锛氱姝腑鏂?/p>

1锛氬綋 usart_sr 瀵勫瓨鍣ㄤ腑 tc=1 鏃讹紝鐢熸垚 usart 涓柇

浣?5 rxneie锛歊xne 涓柇浣胯兘 (rxne interrupt enable)

姝や綅鐢辫蒋浠剁疆 1 鍜屾竻闆躲€?/p>

0锛氱姝腑鏂?/p>

1锛氬綋 usart_sr 瀵勫瓨鍣ㄤ腑 ore=1 鎴?rxne=1 鏃讹紝鐢熸垚 usart 涓柇

浣?4 idleie锛欼dle 涓柇浣胯兘 (idle interrupt enable)

姝や綅鐢辫蒋浠剁疆 1 鍜屾竻闆躲€?/p>

0锛氱姝腑鏂?/p>

1锛氬綋 usart_sr 瀵勫瓨鍣ㄤ腑 idle=1 鏃讹紝鐢熸垚 usart 涓柇

浣?3 te锛氬彂閫佸櫒浣胯兘 (transmitter enable)

璇ヤ綅浣胯兘鍙戦€佸櫒銆傝浣嶇敱杞欢缃?1 鍜屾竻闆躲€?/p>

0锛氱姝㈠彂閫佸櫒

1锛氫娇鑳藉彂閫佸櫒

娉ㄦ剰锛?锛氶櫎浜嗗湪鏅鸿兘鍗℃ā寮忎笅浠ュ锛屼紶閫佹湡闂?te 浣嶄笂鐨勨€?鈥濊剦鍐诧紙鈥?鈥濆悗绱ц窡鐨勬槸鈥?鈥濓級

浼氬湪褰撳墠瀛楃殑鍚庨潰鍙戦€佷竴涓姤澶达紙绌洪棽绾胯矾锛夈€?

2锛氬綋 te 缃?1 鏃讹紝鍦ㄥ彂閫佸紑濮嬪墠瀛樺湪 1 浣嶇殑鏃堕棿寤惰繜銆?

浣?2 re锛氭帴鏀跺櫒浣胯兘 (receiver enable)

璇ヤ綅浣胯兘鎺ユ敹鍣ㄣ€傝浣嶇敱杞欢缃?1 鍜屾竻闆躲€?/p>

0锛氱姝㈡帴鏀跺櫒

1锛氫娇鑳芥帴鏀跺櫒骞跺紑濮嬫悳绱㈣捣濮嬩綅

浣?1 rwu锛氭帴鏀跺櫒鍞ら啋 (receiver wakeup)

璇ヤ綅鍐冲畾 usart 鏄惁澶勪簬闈欓煶妯″紡銆傝浣嶇敱杞欢缃?1 鍜屾竻闆讹紝骞跺彲鍦ㄨ瘑鍒嚭鍞ら啋搴忓垪鏃剁敱纭?/p>

浠舵竻闆躲€?/p>

0锛氭帴鏀跺櫒澶勪簬娲诲姩妯″紡

1锛氭帴鏀跺櫒澶勪簬闈欓煶妯″紡

娉ㄦ剰锛?锛氶€夋嫨闈欓煶妯″紡鍓嶏紙閫氳繃灏?rwu 浣嶇疆 1锛夛紝usart 蹇呴』棣栧厛鎺ユ敹涓€涓暟鎹瓧鑺傦紝鍚﹀垯

褰撶敱绌洪棽绾胯矾妫€娴嬪埌鍞ら啋鏃讹紝瀹冩棤娉曚簬闈欓煶妯″紡涓嬫甯稿伐浣溿€?

2锛氬湪鍦板潃鏍囪妫€娴嬪敜閱掗厤缃紙wake 浣?= 1锛変腑锛孯xne 浣嶇疆 1 鏃讹紝rwu 浣嶄笉鑳界敱杞欢

杩涜淇敼銆?/p>

浣?0 sbk锛氬彂閫佹柇璺?(send break)

璇ヤ綅鐢ㄤ簬鍙戦€佹柇璺瓧绗︺€傝浣嶅彲鐢辫蒋浠剁疆 1 鍜屾竻闆躲€傝浣嶅簲鐢辫蒋浠剁疆 1锛屽苟鍦ㄦ柇璺仠姝綅鏈熼棿

鐢辩‖浠堕噸缃€?/p>

0锛氫笉鍙戦€佹柇璺瓧绗?/p>

1锛氬皢鍙戦€佹柇璺瓧绗?/p>

4.5.5 鎺у埗瀵勫瓨鍣紙usart_cr2锛?/p>

浣?31:15 淇濈暀锛屽繀椤讳繚鎸佸浣嶅€?/p>

浣?14 linen锛歀in 妯″紡浣胯兘 (lin mode enable)

姝や綅鐢辫蒋浠剁疆 1 鍜屾竻闆躲€?/p>

0锛氱姝?lin 妯″紡

1锛氫娇鑳?lin 妯″紡

lin 妯″紡鍙互浣跨敤 usart_cr1 瀵勫瓨鍣ㄤ腑鐨?sbk 浣嶅彂閫?lin 鍚屾鏂矾锛?3 涓綆浣嶏級锛屽苟鍙娴?lin

鍚屾鏂矾銆?/p>

浣?13:12 stop锛氬仠姝綅 (stop bit)

杩欎簺浣嶇敤浜庣紪绋嬪仠姝綅銆?/p>

00锛? 涓仠姝綅

01锛?.5 涓仠姝綅

10锛? 涓仠姝綅

11锛?.5 涓仠姝綅

娉ㄦ剰锛?.5 涓仠姝綅鍜?1.5 涓仠姝綅涓嶉€傜敤浜?uart4 鍜?uart5銆?

浣?11 clken锛氭椂閽熶娇鑳?(clock enable)

璇ヤ綅鍏佽鐢ㄦ埛浣胯兘 sclk 寮曡剼銆?/p>

0锛氱姝?sclk 寮曡剼

1锛氫娇鑳?sclk 寮曡剼

璇ヤ綅涓嶉€傜敤浜?uart4 鍜?uart5銆?

浣?10 cpol锛氭椂閽熸瀬鎬?(clock polarity)

璇ヤ綅鍏佽鐢ㄦ埛鍦ㄥ悓姝ユā寮忎笅閫夋嫨 sclk 寮曡剼涓婃椂閽熻緭鍑虹殑鏋佹€с€傚畠涓?cpha 浣嶇粨鍚堜娇鐢ㄥ彲鑾峰緱鎵€闇€

鐨勬椂閽?鏁版嵁鍏崇郴

0锛氱┖闂叉椂 sclk 寮曡剼涓轰綆鐢靛钩銆?/p>

1锛氱┖闂叉椂 sclk 寮曡剼涓洪珮鐢靛钩銆?/p>

璇ヤ綅涓嶉€傜敤浜?uart4 鍜?uart5銆?/p>

浣?9 cpha锛氭椂閽熺浉浣?/p>

璇ヤ綅鍏佽鐢ㄦ埛鍦ㄥ悓姝ユā寮忎笅閫夋嫨 sclk 寮曡剼涓婃椂閽熻緭鍑虹殑鐩镐綅銆傚畠涓?cpol 浣嶇粨鍚堜娇鐢ㄥ彲鑾峰緱鎵€闇€

鐨勬椂閽?鏁版嵁鍏崇郴锛堣鍙傝鍥?58 鑷?59锛?/p>

0锛氬湪鏃堕挓绗竴涓彉鍖栨部鎹曡幏鏁版嵁

1锛氬湪鏃堕挓绗簩涓彉鍖栨部鎹曡幏鏁版嵁

娉ㄦ剰锛氳浣嶄笉閫傜敤浜?uart4 鍜?uart5銆?

浣?8 lbcl锛氭渶鍚庝竴涓綅鏃堕挓鑴夊啿 (last bit clock pulse)

璇ヤ綅鍏佽鐢ㄦ埛鍦ㄥ悓姝ユā寮忎笅閫夋嫨涓庡彂閫佺殑鏈€鍚庝竴涓暟鎹綅 (msb) 鍏宠仈鐨勬椂閽熻剦鍐叉槸鍚﹀繀椤诲湪 sclk

寮曡剼涓婅緭鍑恒€?/p>

0锛氭渶鍚庝竴涓暟鎹綅鐨勬椂閽熻剦鍐蹭笉鍦?sclk 寮曡剼涓婅緭鍑?/p>

1锛氭渶鍚庝竴涓暟鎹綅鐨勬椂閽熻剦鍐插湪 sclk 寮曡剼涓婅緭鍑?/p>

娉ㄦ剰锛?锛氭渶鍚庝竴浣嶄负鍙戦€佺殑绗?8 鎴栫 9 涓暟鎹綅锛屽叿浣撳彇鍐充簬 usart_cr1 瀵勫瓨鍣ㄤ腑 m 浣嶆墍閫夋嫨鐨?

8 浣嶆垨 9 浣嶆牸寮忋€?

2锛氳浣嶄笉閫傜敤浜?uart4 鍜?uart5銆?

浣?7 淇濈暀锛屽繀椤讳繚鎸佸浣嶅€?/p>

浣?6 lbdie锛歀in 鏂矾妫€娴嬩腑鏂娇鑳?(lin break detection interrupt enable)

鏂矾涓柇灞忚斀锛堜娇鐢ㄦ柇璺垎闅旂杩涜鏂矾妫€娴嬶級

0锛氱姝腑鏂?/p>

1锛氬綋 usart_sr 瀵勫瓨鍣ㄤ腑 lbd = 1 鏃讹紝鐢熸垚涓柇

浣?5 lbdl锛歭in 鏂矾妫€娴嬮暱搴?(lin break detection length)

璇ヤ綅鐢ㄤ簬閫夋嫨 11 浣嶆柇璺娴嬫垨 10 浣嶆柇璺娴嬨€?/p>

0锛?0 浣嶆柇璺娴?/p>

1锛?1 浣嶆柇璺娴?/p>

浣?4 淇濈暀锛屽繀椤讳繚鎸佸浣嶅€?/p>

浣?3:0 add[3:0]锛歎sart 鑺傜偣鐨勫湴鍧€

璇ヤ綅鍩熺敤浜庢寚瀹?usart 鑺傜偣鐨勫湴鍧€銆?/p>

灏嗗湪澶氬鐞嗗櫒閫氫俊鏃朵簬闈欓煶妯″紡涓嬩娇鐢ㄨ浣嶅煙锛屼互閫氳繃鍦板潃鏍囪妫€娴嬭繘琛屽敜閱掋€?/p>

娉ㄦ剰锛?浣胯兘鍙戦€佸櫒鏃朵笉搴斿杩?3 涓綅锛圕pol銆丆pha銆丩bcl锛夎繘琛屽啓鎿嶄綔銆?/p>

4.5.6 鎺у埗瀵勫瓨鍣?锛圲sart_cr3锛?/p>

浣?31:12 淇濈暀锛屽繀椤讳繚鎸佸浣嶅€?/p>

浣?11 onebit锛氫竴涓噰鏍蜂綅鏂规硶浣胯兘 (one sample bit method enable)

璇ヤ綅鍏佽鐢ㄦ埛閫夋嫨閲囨牱鏂规硶銆傞€夋嫨涓€涓噰鏍蜂綅鏂规硶鍚庯紝灏嗙姝㈠櫔澹版娴嬫爣蹇?(nf)銆?/p>

0锛氫笁涓噰鏍蜂綅鏂规硶

1锛氫竴涓噰鏍蜂綅鏂规硶

浣?10 ctsie锛欳ts 涓柇浣胯兘 (cts interrupt enable)

0锛氱姝腑鏂?/p>

1锛氬綋 usart_sr 瀵勫瓨鍣ㄤ腑 cts = 1 鏃讹紝鐢熸垚涓柇

娉ㄦ剰锛氳浣嶄笉閫傜敤浜?uart4 鍜?uart5銆?

浣?9 ctse锛?cts 浣胯兘 (cts enable)

0锛?/p>

绂佹 cts 纭欢娴佹帶鍒?/p>

1锛?/p>

浣胯兘 cts 妯″紡锛屼粎褰?ncts 杈撳叆鏈夋晥 锛堣繛鎺ュ埌 0锛夋椂鎵嶅彂閫佹暟鎹€?/p>

濡傛灉鍦ㄥ彂閫佹暟鎹椂浣?/p>

ncts 杈撳叆鏃犳晥锛屼細鍦ㄥ仠姝箣鍓嶅畬鎴愬彂閫併€?/p>

濡傛灉浣?ncts 鏈夋晥鏃舵暟鎹凡鍐欏叆鏁版嵁瀵勫瓨鍣紝鍒?/p>

灏嗗欢杩熷彂閫侊紝鐩村埌 ncts 鏈夋晥銆?/p>

娉ㄦ剰锛氳浣嶄笉閫傜敤浜?uart4 鍜?uart5銆?

浣?8 rtse锛?rts 浣胯兘 (rts enable)

0锛?/p>

绂佹 rts 纭欢娴佹帶鍒?/p>

1锛?/p>

浣胯兘 rts 涓柇锛屼粎褰撴帴鏀剁紦鍐插尯涓湁绌洪棿鏃舵墠浼氳姹傛暟鎹€?/p>

鍙戦€佸畬褰撳墠瀛楃鍚庡簲鍋滄鍙?/p>

閫佹暟鎹€?/p>

鍙互鎺ユ敹鏁版嵁鏃朵娇 nrts 杈撳嚭鏈夋晥 锛堣繛鎺ュ埌 0锛夈€?/p>

娉ㄦ剰锛氳浣嶄笉閫傜敤浜?uart4 鍜?uart5銆?

浣?7 dmat锛?dma 浣胯兘鍙戦€佸櫒 (dma enable transmitter)

璇ヤ綅鐢辫蒋浠剁疆 1/ 澶嶄綅銆?/p>

1锛?/p>

閽堝鍙戦€佷娇鑳?dma 妯″紡銆?/p>

0锛?/p>

閽堝鍙戦€佺姝?dma 妯″紡銆?/p>

浣?6 dmar锛?dma 浣胯兘鎺ユ敹鍣?(dma enable receiver)

璇ヤ綅鐢辫蒋浠剁疆 1/ 澶嶄綅銆?/p>

1锛?/p>

閽堝鎺ユ敹浣胯兘 dma 妯″紡

0锛氶拡瀵规帴鏀剁姝?dma 妯″紡

浣?5 scen锛氭櫤鑳藉崱妯″紡浣胯兘 (smartcard mode enable)

璇ヤ綅鐢ㄤ簬浣胯兘鏅鸿兘鍗℃ā寮忋€?/p>

0锛?/p>

绂佹鏅鸿兘鍗℃ā寮?/p>

1锛氫娇鑳芥櫤鑳藉崱妯″紡

娉ㄦ剰锛氳浣嶄笉閫傜敤浜?uart4 鍜?uart5銆?

浣?4 nack锛氭櫤鑳藉崱 nack 浣胯兘 (smartcard nack enable)

0锛?/p>

鍑虹幇濂囧伓鏍¢獙閿欒鏃剁姝?nack 鍙戦€?/p>

1锛氬嚭鐜板鍋舵牎楠岄敊璇椂浣胯兘 nack 鍙戦€?/p>

娉ㄦ剰锛氳浣嶄笉閫傜敤浜?uart4 鍜?uart5銆?

浣?3 hdsel锛氬崐鍙屽伐閫夋嫨 (half-duplex selection)

閫夋嫨鍗曠嚎鍗婂弻宸ユā寮?/p>

0锛氭湭閫夋嫨鍗婂弻宸ユā寮?/p>

1锛氶€夋嫨鍗婂弻宸ユā寮?/p>

浣?2 irlp锛欼rda 浣庡姛鑰?(irda low-power)

璇ヤ綅鐢ㄤ簬閫夋嫨姝e父妯″紡鍜屼綆鍔熻€?irda 妯″紡

0锛氭甯告ā寮?/p>

1锛氫綆鍔熻€楁ā寮?/p>

浣?1 iren锛欼rda 妯″紡浣胯兘 (irda mode enable)

姝や綅鐢辫蒋浠剁疆 1 鍜屾竻闆躲€?/p>

0锛氱姝?irda

1锛氫娇鑳?irda

浣?0 eie锛氶敊璇腑鏂娇鑳?(error interrupt enable)

瀵逛簬澶氱紦鍐插尯閫氫俊锛圲sart_cr3 瀵勫瓨鍣ㄤ腑 dmar = 1锛夛紝濡傛灉鍙戠敓甯ч敊璇€佷笂婧㈤敊璇垨鍑?/p>

鐜板櫔澹版爣蹇楋紙usart_sr 瀵勫瓨鍣ㄤ腑 fe = 1 鎴?ore = 1 鎴?nf = 1锛夛紝鍒欓渶瑕佷娇鐢ㄩ敊璇腑鏂?/p>

浣胯兘浣嶆潵浣胯兘涓柇鐢熸垚銆?/p>

0锛氱姝腑鏂?/p>

1锛氬綋 usart_cr3 瀵勫瓨鍣ㄤ腑鐨?dmar = 1 骞朵笖 usart_sr 瀵勫瓨鍣ㄤ腑鐨?fe = 1 鎴?ore = 1

鎴?nf = 1 鏃讹紝灏嗙敓鎴愪腑鏂?/p>

4.5.7 淇濇姢鏃堕棿鍜岄鍒嗛usart_gtpr锛?/p>

浣?31:16 淇濈暀锛屽繀椤讳繚鎸佸浣嶅€?/p>

浣?15:8 gt[7:0]锛?/p>

淇濇姢鏃堕棿鍊?(guard time value)

璇ヤ綅鍩熸彁渚涗繚鎶ゆ椂闂村€?锛堜互娉㈢壒鏃堕挓鏁颁负鍗曚綅锛夈€?/p>

璇ヤ綅鐢ㄤ簬鏅鸿兘鍗℃ā寮忋€?/p>

缁忚繃姝や繚鎶ゆ椂闂村悗锛屽彂閫佸畬鎴愭爣蹇楃疆 1銆?/p>

娉ㄦ剰锛氳浣嶄笉閫傜敤浜?uart4 鍜?uart5銆?

浣?7:0 psc[7:0]锛氶鍒嗛鍣ㄥ€?/p>

鈥?鍦?irda 浣庡姛鑰楁ā寮忎笅锛?

psc[7:0] = irda 浣庡姛鑰楁尝鐗圭巼

鐢ㄤ簬缂栫▼棰勫垎棰戝櫒锛岃繘琛岀郴缁熸椂閽熷垎棰戜互鑾峰緱浣庡姛鑰楅鐜囷細

浣跨敤瀵勫瓨鍣ㄤ腑缁欏嚭鐨勫€硷紙8 涓湁鏁堜綅锛夊婧愭椂閽熻繘琛屽垎棰戯細

00000000锛氫繚鐣?- 涓嶇紪绋嬫鍊?/p>

婧愭椂閽?1 鍒嗛

00000010锛氭簮鏃堕挓 2 鍒嗛

鈥?鍦ㄦ甯?irda 妯″紡涓嬶細psc 蹇呴』璁剧疆涓?00000001銆?/p>

鈥?鍦ㄦ櫤鑳藉崱妯″紡涓嬶細

psc[4:0]锛氶鍒嗛鍣ㄥ€?/p>

鐢ㄤ簬缂栫▼棰勫垎棰戝櫒锛岃繘琛岀郴缁熸椂閽熷垎棰戜互鎻愪緵鏅鸿兘鍗℃椂閽熴€?/p>

灏嗗瘎瀛樺櫒涓粰鍑虹殑鍊硷紙5 涓湁鏁堜綅锛変箻浠?2 寰楀嚭婧愭椂閽熼鐜囩殑鍒嗛绯绘暟锛?/p>

00000锛氫繚鐣?- 涓嶇紪绋嬫鍊?/p>

00001锛氭簮鏃堕挓 2 鍒嗛

00010锛氭簮鏃堕挓 4 鍒嗛

00011锛氭簮鏃堕挓 6 鍒嗛

娉ㄦ剰锛?锛氬鏋滀娇鐢ㄦ櫤鑳藉崱妯″紡锛屽垯浣?[7:5] 涓嶈捣浣滅敤銆?

2锛氳浣嶄笉閫傜敤浜?uart4 鍜?uart5銆?/p>

涓插彛纭欢鐢佃矾

4.5.8 绋嬪簭閰嶇疆姝ラ

rcc閰嶇疆锛氳寮€鐩稿簲鐨凣pio缁勬椂閽熷拰鐩稿簲鐨勪覆鍙f椂閽燂紱gpio閰嶇疆锛氬湪gpio閰嶇疆涓紝灏嗗彂閫佺鐨勭鑴氶厤缃负澶嶇敤鎺ㄦ尳杈撳嚭锛屽皢鎺ユ敹绔殑绠¤剼閰嶇疆涓烘诞绌鸿緭鍏ワ紱usart閰嶇疆锛歎sart瀵勫瓨鍣ㄩ厤缃紱nvic閰嶇疆锛氳缃覆鍙g殑涓柇鎶㈠崰浼樺厛绾у拰浜氫紭鍏堢骇锛涘彂閫?鎺ユ敹鏁版嵁锛氶€氳繃涓插彛瀵勫瓨鍣ㄦ帴鏀?鍙戦€佹暟鎹€?/p>

4.5.9 瀹炰緥浠g爜

#include "usart1.h" // device header

void usart1_init(int bps)

{

gpio_inittypedef u1_txrx;

usart_inittypedef u1;

nvic_inittypedef u1_nvic;

rcc_ahb1periphclockcmd(rcc_ahb1periph_gpioa,enable);

rcc_apb2periphclockcmd(rcc_apb2periph_usart1, enable);

gpio_pinafconfig(gpioa,gpio_pinsource9,gpio_af_usart1);

gpio_pinafconfig(gpioa,gpio_pinsource10,gpio_af_usart1);

//pa9-鍙戦€?/p>

u1_txrx.gpio_mode =gpio_mode_af;

u1_txrx.gpio_otype = gpio_otype_pp;

u1_txrx.gpio_pin = gpio_pin_9;

u1_txrx.gpio_pupd = gpio_pupd_up; //榛樿涓嬫媺

u1_txrx.gpio_speed = gpio_high_speed;

gpio_init(gpioa,&u1_txrx); //鏍规嵁u1_txrx閰嶇疆鐨勫弬鏁拌繘琛屽垵濮嬪寲

//pa10-鎺ユ敹

u1_txrx.gpio_mode =gpio_mode_af;

u1_txrx.gpio_otype = gpio_otype_pp;

u1_txrx.gpio_pin = gpio_pin_10;

u1_txrx.gpio_pupd = gpio_pupd_nopull; //榛樿涓嬫媺

u1_txrx.gpio_speed = gpio_high_speed;

gpio_init(gpioa,&u1_txrx);

//usart

u1.usart_baudrate=bps; //娉㈢壒鐜?/p>

u1.usart_hardwareflowcontrol=usart_hardwareflowcontrol_none; //鏃犵‖浠舵祦

u1.usart_mode=usart_mode_tx|usart_mode_rx; //鍙戦€佸拰鎺ユ敹

u1.usart_parity=usart_parity_no; //鏃犳牎楠?/p>

u1.usart_stopbits=usart_stopbits_1; //鍋滄浣?/p>

u1.usart_wordlength=usart_wordlength_8b; //鏁版嵁浣?/p>

usart_init(usart1, &u1); //鏍规嵁u1閰嶇疆鐨勫弬鏁拌繘琛屽垵濮嬪寲

//璁板緱鍒嗗紑鍐欎腑鏂?/p>

usart_itconfig(usart1, usart_it_rxne,enable); //浣胯兘涓插彛鎺ユ敹涓柇

usart_itconfig(usart1, usart_it_idle,enable); //浣胯兘涓插彛绌洪棽涓柇

u1_nvic.nvic_irqchannel = usart1_irqn;

u1_nvic.nvic_irqchannelpreemptionpriority = 1; //鎶㈠崰涓?

u1_nvic.nvic_irqchannelsubpriority = 1;//鍝嶅簲涓?

u1_nvic.nvic_irqchannelcmd = enable;

nvic_init(&u1_nvic);

usart_cmd(usart1, enable); //浣胯兘涓插彛杩涜宸ヤ綔

}

/********************************************************************

鍑芥暟鍔熻兘锛氫覆鍙?鍙戦€?涓瓧鑺傜殑瀛楃鏁版嵁

鍙傛暟1锛歞ata锛氫綘瑕佸彂閫佺殑鏁版嵁

鍙傛暟2锛氭棤

杩斿洖鍊硷細鏃?/p>

浣滆€咃細xxx

********************************************************************/

void usart1_sendbyte(char data)

{

while(!(usart_getflagstatus(usart1,usart_flag_tc))); //绛夊緟鍒ゆ柇鍙戦€佸瘎瀛樺櫒涓虹┖

usart_senddata(usart1,data);

}

/********************************************************************

鍑芥暟鍔熻兘锛氫覆鍙?鍙戦€佷竴涓插瓧绗︽暟鎹?/p>

鍙傛暟1锛歞ata锛氫綘瑕佸彂閫佺殑鏁版嵁

鍙傛暟2锛氭棤

杩斿洖鍊硷細鏃?/p>

浣滆€咃細xxx

********************************************************************/

void usart1_sendstring(char *data)

{

while(*data != '\0')usart1_sendbyte(*data ); //寰幆鍙戦€侊紝鐩村埌閬囧埌\0锛屽仠姝㈠彂閫?/p>

}

/********************************************************************

鍑芥暟鍔熻兘锛氫覆鍙?鎺ユ敹璇诲彇1涓瓧鑺傜殑瀛楃鏁版嵁

鍙傛暟1锛歞ata锛氫綘瑕佸彂閫佺殑鏁版嵁

鍙傛暟2锛氭棤

杩斿洖鍊硷細鏃?/p>

浣滆€咃細xxx

********************************************************************/

char usart1_readbyte(void)

{

while(!(usart_getflagstatus(usart1,usart_flag_rxne))); //绛夊緟鍒ゆ柇鎺ユ敹瀵勫瓨鍣ㄩ潪绌?/p>

return usart_receivedata(usart1); //璇诲埌鐨勬暟鎹?/p>

}

/*

//鎺ユ敹涓柇

struct u1_data u1={0,0,0}; //瀹氫箟缁撴瀯浣撳彉閲忥紝鍚屾椂鍒濆鍖栦负0

char data;

//涓插彛涓柇鏈嶅姟鍑芥暟锛氭瘡鏀跺埌涓€涓瓧绗︽暟鎹紝cpu閮戒細鍏堟殏鍋滄墍鏈夌▼搴忥紝鑷姩鎵ц涓€娆sart1_irqhandler鍑芥暟

void usart1_irqhandler(void)

{

data=usart_receivedata(usart1); //璇绘暟鎹苟娓呴櫎涓柇鏍囧織浣?/p>

if(data=='\r' || data=='\n')

{

u1.ok_flag=1; //u1.ok_flag=1锛岃鏄庢帴鏀跺畬鎴?/p>

u1.buf[u1.len]='\0'; //娣诲姞缁撴潫绗0

}else {

u1.buf[u1.len ]=data; //娌℃敹鍒癨r\n锛屽氨鎶婃暟鎹瓨鍌ㄥ埌鏁扮粍

}

}

*/

//鎺ユ敹涓柇 绌洪棽涓柇

struct u1_data u1={0,0,0}; //瀹氫箟缁撴瀯浣撳彉閲忥紝鍚屾椂鍒濆鍖栦负0

char data;

//鎺ユ敹涓柇锛氭瘡鏀跺埌涓€涓瓧绗︽暟鎹氨浼氭墽琛屼竴娆sart1_irqhandler涓柇鏈嶅姟鍑芥暟

//绌洪棽涓柇锛氭敹瀹屾暟鎹箣鍚庯紝涓插彛浜х敓绌洪棽锛屼細鑷姩鎵ц涓€娆sart1_irqhandler涓柇鏈嶅姟鍑芥暟

void usart1_irqhandler(void)

{

if(usart_getitstatus(usart1, usart_it_rxne)==set) //鎺ユ敹涓柇锛屽瓨鍌ㄦ暟鎹?/p>

{

u1.buf[u1.len]=usart_receivedata(usart1); //璇绘暟鎹苟娓呴櫎涓柇鏍囧織浣?/p>

u1.len ; //鑷锛屼负涓嬩釜鏁版嵁瀛樺偍鍋氬噯澶?/p>

}else if(usart_getitstatus(usart1, usart_it_idle)==set) //绌洪棽涓柇锛屾帴鏀舵暟鎹粨鏉?/p>

{

usart_clearitpendingbit(usart1, usart_it_idle); //璇籗r

usart_receivedata(usart1); //璇籇r

u1.ok_flag=1; //鎺ユ敹瀹屾垚

u1.buf[u1.len]='\0'; //娣诲姞缁撴潫绗?/p>

}

}

/* 鍛婄煡杩炴帴鍣ㄤ笉浠嶤搴撻摼鎺ヤ娇鐢ㄥ崐涓绘満鐨勫嚱鏁?*/

#pragma import(__use_no_semihosting)

/* 瀹氫箟 _sys_exit() 浠ラ伩鍏嶄娇鐢ㄥ崐涓绘満妯″紡 */

void _sys_exit(int x)

{

x = x;

}

/* 鏍囧噯搴撻渶瑕佺殑鏀寔绫诲瀷 */

struct __file

{

int handle;

};

file __stdout;

/* */

int fputc(int ch, file *stream)

{

/* 鍫靛鍒ゆ柇涓插彛鏄惁鍙戦€佸畬鎴?*/

usart1_sendbyte(ch); //涓插彛鍙戦€佷竴涓瓧绗?/p>

return ch;

}

5.绯荤粺婊寸瓟瀹氭椂鍣?/p>

瀛︿範杩欎釜鎴戜滑瑕佺煡閬撳畾鏃跺櫒閮ㄥ垎瀛︿範鐨勪笁涓洰鐨勶細浜嗚в绯荤粺婊寸瓟瀹氭椂鍣ㄧ殑浣滅敤鏄粈涔堬紵鎺屾彙绯荤粺婊寸瓟瀹氭椂鍣ㄥ瘎瀛樺櫒鐨勯厤缃紱鎺屾彙绯荤粺婊寸瓟瀹氭椂鍣ㄧ殑椹卞姩杞欢璁捐銆?/p>

5.1 绯荤粺婊寸瓟瀹氭椂鍣ㄦ杩?/p>

聽 聽鍦ㄦ垜浠殑cortex-m4褰撲腑锛宻ystick瀹氭椂鍣ㄨ鎹嗙粦鍒版垜浠殑nvic褰撲腑锛岀敤浜庝骇鐢焥ystick寮傚父銆傚湪鎴戜滑stm32鐨凷ystick瀹氭椂鍣ㄦ湁涓や釜鍙€夌殑鏃堕挓婧愶紝涓€涓槸澶栭儴鏃堕挓婧?stclk,绛変簬hclk/8-浠呴檺浜巗tm32f10x),鍙︿竴涓槸鍐呮牳鏃堕挓(fclk锛?绛変簬hclk)銆傚亣鑻ヤ綘閫夋嫨鍐呮牳鏃堕挓锛屽苟灏咹clk棰戠巼璁剧疆涓?2mhz鐨勮瘽锛岀郴缁熸椂閽熷懆鏈熶负1/(168m); systick 鏈変竴涓?4浣嶇殑閫掑噺璁℃暟鍣紝姣忎釜绯荤粺鏃堕挓鍛ㄦ湡璁℃暟鍣ㄥ€煎噺涓€.閭d箞褰撹鏁板櫒鍑忓埌闆舵椂锛屾椂闂寸粡杩囦簡:绯荤粺鏃堕挓鍛ㄦ湡*璁℃暟鍣ㄥ垵鍊笺€傚綋浣犲皢璁℃暟鍣ㄥ垵鍊艰涓?2000鏃讹紝褰撹鏁板櫒鍊煎噺鍒?鏃剁粡杩囦簡1/(72m)*(72000)=0. 001s,鍗?ms.

5.2 绯荤粺婊寸瓟瀹氭椂鍣ㄧ殑浣滅敤

1.浜х敓鎿嶄綔绯荤粺鐨勬椂閽熻妭鎷嶏紱

聽 聽 systick瀹氭椂鍣ㄦā鎹嗙粦鍦∟vic涓紝鐢ㄤ簬浜х敓systick寮傚父(寮傚父鍙? 15)銆傚ぇ澶氭搷浣滅郴缁熼渶瑕佷竴涓‖浠跺畾鏃跺櫒鏉ヤ骇鐢熸搷浣滅郴缁熼渶瑕佺殑婊寸瓑涓柇锛屼綔涓烘暣涓郴缁熺殑鏃跺熀銆傚洜姝わ紝闇€瑕佷竴涓畾鏃跺櫒鏉ヤ骇鐢熷懆鏈熸€х殑涓柇銆傝€屼笖鏈€濂借繕璁╃敤鎴风▼搴忎笉鑳介殢鎰忚闂畠鐨勫瘎瀛樺櫒锛屼互缁存寔鎿嶄綔绯荤粺鈥滃績璺斥€濈殑鑺傚緥銆?/p>

2.鏂逛究浜庝笉鍚屽鐞嗗櫒涔嬮棿鐨勭▼搴忕щ妞嶏紱

cortex鈥滿4澶勭悊鍣ㄥ唴閮ㄥ寘鍚簡涓€涓畝鍗曠殑瀹氭椂鍣ㄣ€傚洜涓烘墍鏈夌殑cm4鑺墖閮藉甫鏈夎繖涓畾鏃跺櫒锛岃蒋浠跺湪涓嶅悓cm4鍣ㄤ欢闂寸殑绉绘宸ヤ綔寰椾互鍖栫畝銆傝瀹氭椂鍣ㄧ殑鏃堕挓婧愬彲浠ユ槸鍐呴儴鏃堕挓(fclk锛?cm4涓婄殑鑷敱杩愯鏃堕挓)锛屾垨鑰呮槸澶栭儴鏃堕挓(cm4澶勭悊鍣ㄤ笂鐨凷tclk淇″彿)銆備笉杩囷紝stclk 鐨勫叿浣撴潵婧愬垯鐢辫姱鐗囪璁¤€呭喅瀹氾紝鍥犳涓嶅悓浜у搧涔嬮棿鐨勬椂閽熼鐜囧彲鑳戒細澶т笉鐩稿悓锛屼綘闇€瑕佹瑙嗚姱鐗囩殑鍣ㄤ欢鎵嬪唽鏉ュ喅瀹氶€夋嫨浠€涔堜綔涓烘椂閽熸簮銆係ystick瀹氭椂鍣ㄨ兘浜х敓涓柇锛孋m4涓哄畠涓撻棬寮€鍑轰竴涓紓甯哥被鍨嬶紝骞朵笖鍦ㄥ悜閲忚〃涓湁瀹冪殑涓€甯箣鍦般€傚畠浣挎搷浣滅郴缁熷拰鍏跺畠绯荤粺杞欢鍦–m4鍣ㄤ欢闂寸殑绉绘鍙樺緱绠€鍗曞浜嗭紝鍥犱负鍦ㄦ墍 鏈塁m4浜у搧闂村鍏跺鐞嗛兘鏄浉鍚岀殑銆?/p>

3.浣滀负涓€涓椆閽熺敤鏉ユ祴閲忔椂闂达紱

聽 聽systick瀹氭椂鍣ㄩ櫎浜嗚兘鏈嶅姟浜庢搷浣滅郴缁熶箣澶栵紝杩樿兘鐢ㄤ簬鍏跺畠鐩殑:濡備綔涓轰竴涓椆閾冿紝鐢ㄤ簬娴嬮噺鏃堕棿绛夈€傝娉ㄦ剰鐨勬槸锛屽綋澶勭悊鍣ㄥ湪璋冭瘯鏈熼棿琚枈鍋?halt) 鏃讹紝鍒橲ystick瀹氭椂鍣ㄤ害灏嗘殏鍋滆繍浣溿€?/p>

5.3 绯荤粺婊寸瓟瀹氭椂鍣ㄥ瘎瀛樺櫒

systick瀵勫瓨鍣?

瀵勫瓨鍣ㄥ悕鎻忚堪ctrlsystick鎺у埗鍜岀姸鎬佸瘎瀛樺櫒loadsystick閲嶈杞藉€煎瘎瀛樺櫒valsystick褰撳墠鍊煎瘎瀛樺櫒calibsystick鏍″噯鍊煎瘎瀛樺櫒

鏇村姞璇︾粏鐨勮鏄庡ぇ瀹跺彲浠ュ埌鐩稿叧鍥轰欢搴撴墜鍐岃嚜琛屾煡闃呭摝锛伮?/p>

5.5 浠g爜瀹炰緥

鎴戜滑浣跨敤鐨勬槸鍦ㄨ8鏈虹姸鎬佷笅瀹屾垚鐨勶紝鍥犱负鍦ㄩ€昏緫鐘舵€佷笅鐨勫師鍥狅紝鎵€浠ュ彲浠ヤ娇鐢ㄧ郴缁熸淮绛斿畾鏃跺櫒浜х敓绮惧噯寤舵椂锛?/p>

#include "delay.h" // device header

//绯荤粺婊寸瓟寤舵椂鍒濆鍖?/p>

void systick_init(void)

{

systick->ctrl &=~(1<<2); //閫夋嫨澶栭儴鏃堕挓婧愶紝systick鏃堕挓涓婚涓?68/8=21mhz

}

//鏈€澶х殑us寤舵椂鏃堕棿锛?4浣嶆渶澶у€?6777215/21=798915us,杞崲涓簃s锛?98.915ms

void delay_us(int us)

{

systick->load = us*21; //1us*9涓暟锛屽紑濮嬭鏁板墠锛屽厛濉厖濂借鏁版椂闂寸殑鍊?/p>

systick->ctrl |=1<<0; //浣胯兘瀹氭椂鍣?寮€濮嬪悜涓嬭鏁?/p>

systick->val=0; //娓呴櫎0

while(!(systick->ctrl & 1<<16)); //绛夊緟涔嬪墠濉厖濂借鏁版椂闂寸殑鍊间负0锛屽欢鏃舵椂闂村埌

systick->ctrl &=~(1<<0); //鍏抽棴瀹氭椂鍣?/p>

systick->val=0; //娓呴櫎0

}

//鏈€澶х殑us寤舵椂鏃堕棿锛?4浣嶆渶澶у€?6777215/21=798915us,杞崲涓簃s锛?98.915ms

void delay_nms(int nms)

{

systick->load = nms*21000; //1us*21000涓暟锛屽紑濮嬭鏁板墠锛屽厛濉厖濂借鏁版椂闂寸殑鍊?/p>

systick->ctrl |=1<<0; //浣胯兘瀹氭椂鍣?寮€濮嬪悜涓嬭鏁?/p>

while(!(systick->ctrl & 1<<16)); //绛夊緟涔嬪墠濉厖濂借鏁版椂闂寸殑鍊间负0锛屽欢鏃舵椂闂村埌

systick->ctrl &=~(1<<0); //鍏抽棴瀹氭椂鍣?/p>

}

//鍑芥暟鍔熻兘锛氬皢ms杩涜鎵╁ぇ

void delay_ms(int ms)

{

int i;

int beishu=ms/500; //寰幆璋冪敤鍊嶆暟

int yushu=msp0; //寰幆璋冪敤浣欐暟

for(i=0;i

{

delay_nms(500);

}

if(yushu!=0)delay_nms(yushu); //浣欐暟

}

6.瀹氭椂鍣?/p>

6.1 閫氱敤瀹氭椂鍣?/p>

浠€涔堟槸閫氱敤瀹氭椂鍣紵鏄竴涓彲浠ラ€氳繃鍙紪绋嬮鍒嗛鍣ㄩ┍鍔ㄧ殑16浣嶈嚜鍔ㄨ杞借鏁板櫒銆傚彲浠ョ敤浜庡緢澶氬満鍚堬紝姣斿娴嬮噺杈撳叆淇″彿鐨勮剦鍐查暱搴︼紙杈撳叆鎹曡幏锛夋垨鑰呬骇鐢熻緭鍑烘尝褰紙杈撳嚭鍜孭wm锛夈€備娇鐢ㄥ畾鏃跺櫒棰勫垎棰戝櫒鍜孯cc鏃堕挓鎺у埗鍣ㄩ鍒嗛鍣紝鑴夊啿闀垮害鍜屾尝褰㈠懆鏈熷彲浠ュ湪鍑犱釜寰鍒板嚑姣闂寸殑璋冩暣銆傛瘡涓畾鏃跺櫒閮芥槸瀹屽叏鐙珛鐨勶紝娌℃湁浜掔浉鍏变韩鐨勪换浣曡祫婧愶紒

6.2 stm32f4绯诲垪閫氱敤瀹氭椂鍣ㄧ壒鐐?/p>

瀹氭椂鍣ㄥ熀鏈鏋跺浘

聽16浣嶅悜涓娿€佸悜涓嬨€佸悜涓?鍚戜笅鑷姩瑁呰浇璁℃暟鍣?6浣嶅彲缂栫▼棰勫垎棰戝櫒锛岃鏁板櫒鏃堕挓棰戠巼鐨勫垎棰戠郴鏁颁负1-65536涔嬮棿鐨勪换鎰忔暟鍊硷紱4涓嫭绔嬮€氶亾锛?-杈撳叆鎹曡幏锛涗竴杈撳嚭姣旇緝锛涗竴pwm鐢熸垚(杈圭紭鎴栦腑闂村榻愭ā寮?锛涗竴鍗曡剦鍐叉ā寮忚緭鍑?/p>

姝诲尯鏃堕棿鍙紪绋嬬殑浜掕ˉ杈撳嚭浣跨敤澶栭儴淇?鍙锋帶鍒跺畾鏃?鍣ㄥ拰瀹氭椂鍣ㄤ簰鑱旂殑鍚屾鐢佃矾鍏佽鍦ㄦ寚瀹氭暟鐩殑璁℃暟鍣ㄥ懆鏈熶箣鍚庢洿鏂板畾鏃跺櫒瀵勫瓨鍣ㄧ殑閲嶅璁℃暟鍣ㄥ埞杞﹁緭鍏ヤ俊鍙峰彲浠ュ皢瀹氭椂鍣ㄨ緭鍑轰俊鍙风疆浜庡浣嶇姸鎬佹垨鑰呬竴涓凡鐭ョ姸鎬佸涓嬩簨浠跺彂鐢熸椂浜х敓涓柇/dma :

聽 聽 聽 聽 聽 ---鏇存柊:璁℃暟鍣ㄥ悜涓婃孩鍑哄悜涓嬫粙鍑猴紝璁℃暟鍣ㄥ垵濮嬪寲(閫氳繃杞欢鎴栬€呭唴閮?澶栭儴瑙﹀彂) 聽 聽 聽 聽 聽 涓€瑙﹀彂浜嬩欢(璁℃暟鍣ㄥ惎鍔ㄣ€佸仠姝€佸垵濮嬪寲鎴栬€呯敱鍐呴儴/澶栭儴瑙﹀彂璁℃暟) 聽 聽 聽 聽 聽 涓€杈撳叆鎹曡幏 聽 聽 聽 聽 聽 涓€杈撳嚭姣旇緝 聽 聽 聽 聽 聽 涓€鍒硅溅淇″彿杈撳叆

鏀寔璁″瀹氫綅鐨勫閲?姝d氦)缂栫爜鍣ㄥ拰闇嶅皵浼犳劅鍣ㄧ數璺е鍙戣緭鍏ヤ綔涓哄閮ㄦ椂閽熸垨鑰呮寜鍛ㄦ湡鐨勭數娴佺鐞?/p>

6.3 涓庡熀鏈畾鏃跺櫒鐩稿叧鐨勫瘎瀛樺櫒

6.3.1 tim6鍜孴im7鎺у埗瀵勫瓨鍣?锛圱imx_cr1锛?/p>

聽浣?15:8 淇濈暀锛屽繀椤讳繚鎸佸浣嶅€笺€?

浣?7 arpe锛氳嚜鍔ㄩ噸杞介瑁呰浇浣胯兘 (auto-reload preload enable)

0

锛?/p>

timx_arr

瀵勫瓨鍣ㄤ笉杩涜缂撳啿銆?

1

锛?/p>

timx_arr

瀵勫瓨鍣ㄨ繘琛岀紦鍐层€?

浣?6:4 淇濈暀锛屽繀椤讳繚鎸佸浣嶅€笺€?

浣?3 opm锛氬崟鑴夊啿妯″紡 (one-pulse mode)

0

锛氳鏁板櫒鍦ㄥ彂鐢熸洿鏂颁簨浠舵椂涓嶄細鍋滄璁℃暟

1

锛氳鏁板櫒鍦ㄥ彂鐢熶笅涓€鏇存柊浜嬩欢鏃跺仠姝㈣鏁帮紙灏?/p>

cen

浣嶆竻闆讹級銆?

浣?2 urs锛氭洿鏂拌姹傛簮 (update request source)

姝や綅鐢辫蒋浠剁疆

1

鍜屾竻闆讹紝鐢ㄤ互閫夋嫨

uev

浜嬩欢婧愩€?

0

锛氫娇鑳芥椂锛屾墍鏈変互涓嬩簨浠堕兘浼氱敓鎴愭洿鏂颁腑鏂垨

dma

璇锋眰銆傛绫讳簨浠跺寘鎷細

鈥?

璁℃暟鍣ㄤ笂婧?/p>

/

涓嬫孩

鈥?

灏?/p>

ug

浣嶇疆

1

鈥?

閫氳繃浠庢ā寮忔帶鍒跺櫒鐢熸垚鐨勬洿鏂颁簨浠?

1

锛氫娇鑳芥椂锛屽彧鏈夎鏁板櫒涓婃孩

/

涓嬫孩浼氱敓鎴愭洿鏂颁腑鏂垨

dma

璇锋眰銆?

浣?1 udis锛氭洿鏂扮姝?(update disable)

姝や綅鐢辫蒋浠剁疆

1

鍜屾竻闆讹紝鐢ㄤ互浣胯兘

/

绂佹

uev

浜嬩欢鐢熸垚銆?

0

锛氫娇鑳?/p>

uev

銆傛洿鏂?/p>

(uev)

浜嬩欢鍙€氳繃浠ヤ笅浜嬩欢涔嬩竴鐢熸垚锛?

鈥?

璁℃暟鍣ㄤ笂婧?/p>

/

涓嬫孩

鈥?

灏?/p>

ug

浣嶇疆

1

鈥?

閫氳繃浠庢ā寮忔帶鍒跺櫒鐢熸垚鐨勬洿鏂颁簨浠?

鐒跺悗鏇存柊褰卞瓙瀵勫瓨鍣ㄧ殑鍊笺€?

1

锛氱姝?/p>

uev

銆備笉浼氱敓鎴愭洿鏂颁簨浠讹紝鍚勫奖瀛愬瘎瀛樺櫒鐨勫€硷紙

arr

鍜?/p>

psc

锛変繚鎸佷笉鍙樸€備絾濡傛灉灏?

ug

浣嶇疆

1

锛屾垨鑰呬粠浠庢ā寮忔帶鍒跺櫒鎺ユ敹鍒扮‖浠跺浣嶏紝鍒欎細閲嶆柊鍒濆鍖栬鏁板櫒鍜岄鍒嗛鍣ㄣ€?/p>

浣?0 cen锛氳鏁板櫒浣胯兘 (counter enable)

0

锛氱姝㈣鏁板櫒

1

锛氫娇鑳借鏁板櫒

娉ㄦ剰锛氬彧鏈変簨鍏堥€氳繃杞欢灏?/p>

cen

浣嶇疆

1

锛屾墠鍙互浣跨敤闂ㄦ帶妯″紡銆傝€岃е鍙戞ā寮忓彲閫氳繃纭欢鑷姩灏?

cen

浣嶇疆

1

銆?

鍦ㄥ崟鑴夊啿妯″紡涓嬶紝褰撳彂鐢熸洿鏂颁簨浠舵椂浼氳嚜鍔ㄥ皢

cen

浣嶆竻闆躲€?/p>

6.3.2 tim6鍜孴im7鎺у埗瀵勫瓨鍣?锛圱imx_cr2锛?/p>

浣?15:7 淇濈暀锛屽繀椤讳繚鎸佸浣嶅€笺€?

浣?6:4 mms锛氫富妯″紡閫夋嫨 (master mode selection)

杩欎簺浣嶇敤浜庨€夋嫨涓绘ā寮忎笅灏嗚鍙戦€佸埌浠庡畾鏃跺櫒浠ュ疄鐜板悓姝ョ殑淇℃伅

(trgo)

銆傝繖浜涗綅鐨勭粍鍚堝涓嬶細

000

锛?/p>

澶嶄綅

鈥斺€?/p>

timx_egr

瀵勫瓨鍣ㄤ腑鐨?/p>

ug

浣嶇敤浣滆е鍙戣緭鍑?/p>

(trgo)

銆傚鏋滃浣嶇敱瑙﹀彂杈撳叆

鐢熸垚锛堜粠妯″紡鎺у埗鍣ㄩ厤缃负澶嶄綅妯″紡锛夛紝鍒?/p>

trgo

涓婄殑淇″彿鐩告瘮瀹為檯澶嶄綅浼氭湁寤惰繜銆?

001

锛?/p>

浣胯兘

鈥斺€旇鏁板櫒浣胯兘淇″彿

(cnt_en)

鐢ㄤ綔瑙﹀彂杈撳嚭

(trgo)

銆傝瑙﹀彂杈撳嚭鍙敤浜庡悓鏃?

鍚姩澶氫釜瀹氭椂鍣紝鎴栬€呮帶鍒跺湪涓€娈垫椂闂村唴浣胯兘浠庡畾鏃跺櫒銆傝鏁板櫒浣胯兘淇″彿鐢?/p>

cen

鎺у埗浣嶄笌

闂ㄦ帶妯″紡涓嬬殑瑙﹀彂杈撳叆鐨勯€昏緫鎴栬繍绠楃粍鍚堣€屾垚銆?

褰撹鏁板櫒浣胯兘淇″彿鐢辫е鍙戣緭鍏ユ帶鍒舵椂锛?/p>

trgo

涓婁細瀛樺湪寤惰繜锛岄€夋嫨涓?/p>

/

浠庢ā寮忔椂闄ゅ锛堣鍙傝

timx_smcr

瀵勫瓨鍣ㄤ腑瀵?/p>

msm

浣嶇殑璇存槑锛夈€?

010

锛?/p>

鏇存柊

鈥斺€旈€夋嫨鏇存柊浜嬩欢浣滀负瑙﹀彂杈撳嚭

(trgo)

銆備緥濡傦紝涓诲畾鏃跺櫒鍙敤浣滀粠瀹氭椂鍣ㄧ殑棰勫垎

棰戝櫒銆?

浣?3:0 淇濈暀锛屽繀椤讳繚鎸佸浣嶅€笺€?/p>

6.3.3聽tim6 鍜?tim7 dma/涓柇浣胯兘瀵勫瓨鍣?(timx_dier)

浣?15:9 淇濈暀锛屽繀椤讳繚鎸佸浣嶅€?/p>

浣?8 ude锛氭洿鏂?dma 璇锋眰浣胯兘 (update dma request enable)

0

锛氱姝㈡洿鏂?/p>

dma

璇锋眰銆?

1

锛氫娇鑳芥洿鏂?/p>

dma

璇锋眰銆?

浣?7:1 淇濈暀锛屽繀椤讳繚鎸佸浣嶅€?/p>

浣?0 uie锛氭洿鏂颁腑鏂娇鑳?(update interrupt enable)

0

锛氱姝㈡洿鏂颁腑鏂€?

1

锛氫娇鑳芥洿鏂颁腑鏂€?/p>

6.3.4 tim6鍜孴im7鐘舵€佸瘎瀛樺櫒锛圱imx_sr锛?/p>

浣?15:1 淇濈暀锛屽繀椤讳繚鎸佸浣嶅€笺€?

浣?0 uif锛氭洿鏂颁腑鏂爣蹇?(update interrupt flag)

璇ヤ綅鍦ㄥ彂鐢熸洿鏂颁簨浠舵椂閫氳繃纭欢缃?/p>

1

銆備絾闇€瑕侀€氳繃杞欢娓呴浂銆?

0

锛氭湭鍙戠敓鏇存柊銆?

1

锛氭洿鏂颁腑鏂寕璧枫€傝浣嶅湪浠ヤ笅鎯呭喌涓嬫洿鏂板瘎瀛樺櫒鏃剁敱纭欢缃?/p>

1

锛?

鈥?

涓婃孩鎴栦笅婧㈠苟涓斿綋

timx_cr1

瀵勫瓨鍣ㄤ腑

udis = 0

鏃躲€?

鈥?

褰撶敱浜?/p>

timx_cr1

瀵勫瓨鍣ㄤ腑

urs = 0

涓?/p>

udis = 0

鑰岄€氳繃杞欢浣跨敤

timx_egr

瀵勫瓨鍣ㄤ腑

鐨?/p>

ug

浣嶉噸鏂板垵濮嬪寲

cnt

鏃躲€?

6.3.5聽tim6鍜孴im7浜嬩欢鐢熶骇瀵勫瓨鍣紙timx_egr锛?/p>

浣?15:1 淇濈暀锛屽繀椤讳繚鎸佸浣嶅€笺€?

浣?0 ug锛氭洿鏂扮敓鎴?(update generation)

璇ヤ綅鍙€氳繃杞欢缃?/p>

1

锛屽苟鐢辩‖浠惰嚜鍔ㄦ竻闆躲€?

0

锛氫笉鎵ц浠讳綍鎿嶄綔銆?

1

锛氶噸鏂板垵濮嬪寲瀹氭椂鍣ㄨ鏁板櫒骞剁敓鎴愬瘎瀛樺櫒鏇存柊浜嬩欢銆傝娉ㄦ剰锛岄鍒嗛鍣ㄨ鏁板櫒涔熷皢娓呴浂锛堜絾

棰勫垎棰戞瘮涓嶅彈褰卞搷锛夈€?/p>

6.3.6聽tim6鍜孴im7璁℃暟鍣紙timx_cnt锛?/p>

6.3.7 tim6鍜孴im7棰勫垎棰戝櫒锛圱imx_psc锛?/p>

浣?15:0 psc[15:0]锛氶鍒嗛鍣ㄥ€?(prescaler value)

璁℃暟鍣ㄦ椂閽熼鐜?/p>

ck_cnt

绛変簬

f

ck_psc

/ (psc[15:0] 1)

銆?

psc

鍖呭惈鍦ㄦ瘡娆″彂鐢熸洿鏂颁簨浠舵椂瑕佽杞藉埌瀹為檯棰勫垎棰戝櫒瀵勫瓨鍣ㄧ殑鍊笺€?/p>

6.3.8聽tim6鍜孴im7鑷姩閲嶈浇瀵勫瓨鍣紙timx_arr锛?/p>

聽浣?15:0 arr[15:0]锛氳嚜鍔ㄩ噸杞藉€?(auto-reload value)

arr

涓鸿瑁呰浇鍒板疄闄呰嚜鍔ㄩ噸杞藉瘎瀛樺櫒鐨勫€笺€?

褰撹嚜鍔ㄩ噸杞藉€间负绌烘椂锛岃鏁板櫒涓嶅伐浣?/p>

6.4 瀹炰緥浠g爜

#include "tim4.h" // device header

#include "stdio.h"

void tim4_init(u16 psc,u16 arr)

{

tim_timebaseinittypedef tim4;

nvic_inittypedef nvic_tim4;

rcc_apb1periphclockcmd(rcc_apb1periph_tim4, enable); //浣胯兘瀹氭椂鍣?鏃堕挓

tim4.tim_clockdivision=tim_ckd_div1;

tim4.tim_countermode=tim_countermode_down;

tim4.tim_period=arr;

tim4.tim_prescaler=psc-1;

tim4.tim_repetitioncounter=0;

tim_timebaseinit(tim4, &tim4); //鍒濆鍖栧畾鏃跺櫒4鐨勯厤缃?/p>

tim_itconfig(tim4,tim_it_update, enable); //浣胯兘鏇存柊涓柇

nvic_tim4.nvic_irqchannel=tim4_irqn; //璁剧疆鐨凬vic浼樺厛绾х殑涓柇缂栧彿

nvic_tim4.nvic_irqchannelcmd=enable;

nvic_tim4.nvic_irqchannelpreemptionpriority=2; //鎶㈠崰浼樺厛绾?/p>

nvic_tim4.nvic_irqchannelsubpriority=0; //鍝嶅簲浼樺厛绾?/p>

nvic_init(&nvic_tim4);

tim_cmd(tim4, enable);

}

//涓柇鏈嶅姟鍑芥暟

void tim4_irqhandler(void)

{

tim_clearitpendingbit(tim4, tim_it_update); //娓呴櫎鏇存柊涓柇

printf("1s鏃堕棿鍒癨r\n");

}

7.rtc瀹炴椂鏃堕挓

7.1 绠€浠?/p>

聽 浠€涔堟槸瀹炴椂鏃堕挓锛熷疄鏃舵椂閽烺tc鏄竴涓嫭绔嬬殑瀹氭椂鍣ㄣ€俁tc妯″潡鎷ユ湁涓€缁勮繛缁鏁扮殑璁℃暟鍣紝鍦ㄧ浉搴旇蒋浠堕厤缃笅锛屽彲浠ヤ緵搴旀椂閽熸棩鍘嗙殑鍔熻兘銆備慨鏀硅鏁板櫒鐨勬暟鍊煎彲浠ラ噸鏂拌缃綋鍓嶇殑鏃堕棿鍜屾棩鏈熴€俁tc妯″潡鍜屾椂閽熼厤缃郴缁燂紙rcc_bdcr瀵勫瓨鍣級澶勪簬鍚庡鍖哄煙锛屽嵆鍦ㄧ郴缁熷浣嶆垨寰呮満妯″紡鍞ら啋浠ュ悗锛孯tc鐨勮缃拰浜嬩欢缁存寔涓嶅彉銆俁tc鐢辫嚜甯︾殑鐢垫簮寮曡剼vbat渚涚數锛孷bat鍙互鍜岃搫鐢垫睜鐩镐簰杩炴帴锛屼篃鍙互鍜屽閮ㄧ殑3.3v鐢垫簮寮曡剼鐩歌繛鎺ユ垨淇濇寔鏂紑锛?/p>

聽 ps锛歊tc鏄竴涓郴缁熷畾鏃跺櫒涓嫭绔嬪嚭鏉ョ殑璁惧锛岀敤浜庤缃郴缁熸椂閽燂紝鎻愪緵鎶ヨ鍣ㄦ垨鍛ㄦ湡鎬х殑瀹氭椂鍣ㄣ€?/p>

7.2 stm32f4绯诲垪rtc鐗圭偣

鍖呭惈閲岀銆佺锛屽垎閽熴€佸皬鏃? 12/24 灏忔椂鍒?銆佹槦鏈熷効锛屾棩鏈熴€佹湀浠藉拰骞翠唤鐨勬棩鍘嗐€傝蒋浠跺彲缂栫▼鐨勫浠ゆ椂琛ュ伩銆備袱涓叿鏈変腑鏂姛鑳界殑鍙紪绋嬬綉閽熴€傚彲閫氳繃浠绘剰鏃ュ巻瀛楁鐨勭粍鍚堥┍鍔ㄩ椆閽熴€傝嚜鍔ㄥ敜閱掑崟鍏冿紝鍙懆鏈熸€у湴鐢熸垚鏍囧織浠ヨе鍙戣嚜鍔ㄥ敜閱掍腑鏂€傚弬鑰冩椂閽熸娴?鍙娇鐢ㄦ洿鍔犵簿纭殑绗簩鏃堕挓婧?50 hz鎴?0 hz)鏉ユ彁楂樻棩鍘嗙殑绮剧‘搴︺€傚埄鐢ㄤ簹绉掔骇绉讳綅鐗规€т笌澶栭儴鏃堕挓瀹炵幇绮剧‘鍚屾銆傚彲灞忚斀涓柇/浜嬩欢:聽 聽 聽涓€闂归挓a锛浡?聽 --闂归挓b聽 聽 鍞ら啋涓柇聽 聽 -鏃堕棿鎴陈?聽涓€鍏ヤ镜妫€娴嬫暟瀛楁牎鍑嗙數璺?鍛ㄦ湡鎬ц鏁板櫒璋冩暣)涓€绮惧害涓?ppa-绮惧害涓?. 95 ppa,鍦ㄦ暟绉掗挓鐨勬牎鍑嗙獥鍙d腑鑾峰彇鐢ㄤ簬浜嬩欢淇濆瓨鐨勬椂闂存埑鍔熻兘( 1涓簨浠?鍏ヤ镜妫€娴?涓€2涓甫鍙兘缃繃閫熷櫒鍜屽唴閮ㄤ笂鎷夌殑鍏ヤ镜浜嬩欢20涓浠藉瘎瀛樺櫒80瀛楄妭) .鍙戠敓鍏ヤ镜妫€娴嬩簨浠舵椂锛屽皢澶嶄綅澶囦唤瀵勫瓨鍣?聽

澶嶇敤鍔熻兘杈撳嚭 (rtc_out)锛屽彲閫夋嫨浠ヤ笅涓や釜杈撳嚭涔嬩竴锛?

鈥?rtc_calib

锛?/p>

512 hz

鎴?/p>

1 hz

鏃堕挓杈撳嚭锛?/p>

lse

棰戠巼涓?/p>

32.768 khz)

銆?

鍙€氳繃灏?/p>

rtc_cr

瀵勫瓨鍣ㄤ腑鐨?/p>

coe[23]

浣嶇疆

1

鏉ヤ娇鑳芥杈撳嚭銆傝杈撳嚭鍙繛鎺ュ埌鍣?

浠?/p>

rtc_af1

鍔熻兘銆?

鈥?rtc_alarm

锛堥椆閽?/p>

a

銆侀椆閽?/p>

b

鎴栧敜閱掞級銆?

鍙€氳繃閰嶇疆

rtc_cr

瀵勫瓨鍣ㄧ殑

osel[1:0]

浣嶉€夋嫨姝よ緭鍑恒€傝杈撳嚭鍙繛鎺ュ埌鍣ㄤ欢

rtc_af1

鍔熻兘銆?

rtc 澶嶇敤鍔熻兘杈撳叆锛?

鈥?rtc_ts

锛氭椂闂存埑浜嬩欢妫€娴嬨€傝杈撳叆鍙繛鎺ュ埌鍣ㄤ欢

rtc_af1

鍜?/p>

rtc_af2

鍔熻兘銆?

鈥?rtc_tamp1

锛?/p>

tamper1

浜嬩欢妫€娴嬨€傝杈撳叆鍙繛鎺ュ埌鍣ㄤ欢

rtc_af1

鍜?/p>

rtc_af2

鍔熻兘銆?

鈥?rtc_tamp2

锛?/p>

tamper2

浜嬩欢妫€娴嬨€?

鈥?rtc_refin

锛氬弬鑰冩椂閽熻緭鍏ワ紙閫氬父涓哄競鐢碉紝

50 hz

鎴?/p>

60 hz

锛夈€?/p>

rtc妗嗘灦鍥?

7.3 rtc 鍒濆鍖栧拰閰嶇疆

7.3.1 瀵勫瓨鍣ㄨ闂?/p>

聽 rtc

瀵勫瓨鍣ㄤ负

32

浣嶅瘎瀛樺櫒銆傞櫎浜嗗綋

bypshad=0

鏃跺鏃ュ巻褰卞瓙瀵勫瓨鍣ㄦ墽琛岀殑璇昏闂箣澶栵紝

apb

鎺ュ彛浼氬湪璁块棶

rtc

瀵勫瓨鍣ㄦ椂寮曞叆

2

涓瓑寰呭懆鏈熴€?/p>

7.3.2聽瀵勫瓨鍣ㄥ啓淇濇姢

聽 聽绯荤粺澶嶄綅鍚庯紝鍙€氳繃

pwr

鐢垫簮鎺у埗瀵勫瓨鍣?/p>

(pwr_cr)

鐨?/p>

dbp

浣嶄繚鎶?/p>

rtc

瀵勫瓨鍣ㄤ互闃叉

闈炴甯哥殑鍐欒闂€傚繀椤诲皢

dbp

浣嶇疆

1

鎵嶈兘浣胯兘

rtc

瀵勫瓨鍣ㄧ殑鍐欒闂€?

涓婄數澶嶄綅鍚庯紝鎵€鏈?/p>

rtc

瀵勫瓨鍣ㄥ潎鍙楀埌鍐欎繚鎶ゃ€傞€氳繃鍚戝啓淇濇姢瀵勫瓨鍣?/p>

(rtc_wpr)

鍐欏叆涓€涓?

瀵嗛挜鏉ヤ娇鑳藉

rtc

瀵勫瓨鍣ㄧ殑鍐欐搷浣溿€?

瑕佽в閿佹墍鏈?/p>

rtc

瀵勫瓨鍣紙

rtc_isr[13:8]

銆?/p>

rtc_tafcr

鍜?/p>

rtc_bkpxr

闄ゅ锛夌殑鍐欎繚鎶わ紝

闇€瑕佹墽琛屼互涓嬫楠わ細

1. 灏嗏€?xca

鈥濆啓鍏?/p>

rtc_wpr

瀵勫瓨鍣ㄣ€?

2. 灏嗏€?x53

鈥濆啓鍏?/p>

rtc_wpr

瀵勫瓨鍣ㄣ€?

鍐欏叆涓€涓敊璇殑鍏抽敭瀛椾細鍐嶆婵€娲诲啓淇濇姢銆?

淇濇姢鏈哄埗涓嶅彈绯荤粺澶嶄綅褰卞搷

7.3.3聽鏃ュ巻鍒濆鍖栧拰閰嶇疆

瑕佺紪绋嬪寘鎷椂闂存牸寮忓拰棰勫垎棰戝櫒閰嶇疆鍦ㄥ唴鐨勫垵濮嬫椂闂村拰鏃ユ湡鏃ュ巻鍊硷紝闇€鎸夌収浠ヤ笅椤哄簭鎿嶄綔锛?

灏?rtc_isr 瀵勫瓨鍣ㄤ腑鐨?init 浣嶇疆 1 浠ヨ繘鍏ュ垵濮嬪寲妯″紡銆傚湪姝ゆā寮忎笅锛屾棩鍘嗚鏁板櫒灏嗗仠

聽 聽 聽 聽姝㈠伐浣滃苟涓斿叾鍊煎彲鏇存柊銆?

杞 rtc_isr 瀵勫瓨鍣ㄤ腑鐨?initf 浣嶃€傚綋 initf 缃?1 鏃惰繘鍏ュ垵濮嬪寲闃舵妯″紡銆傚ぇ绾﹂渶瑕?

聽 聽 聽 聽2

涓?/p>

rtcclk

鏃堕挓鍛ㄦ湡锛堢敱浜庢椂閽熷悓姝ワ級銆?

瑕佷负鏃ュ巻璁℃暟鍣ㄧ敓鎴?1 hz 鏃堕挓锛屽簲棣栧厛缂栫▼ rtc_prer 瀵勫瓨鍣ㄤ腑鐨勫悓姝ラ鍒嗛绯绘暟锛?

聽 聽 聽 聽鐒跺悗缂栫▼寮傛棰勫垎棰戠郴鏁般€傚嵆浣垮彧闇€瑕佹洿鏀硅繖涓や釜瀛楁涓箣涓€锛屼篃蹇呴』瀵?/p>

rtc_prer

聽 聽 聽 聽 瀵勫瓨鍣ㄦ墽琛屼袱娆″崟鐙殑鍐欒闂€?

鍦ㄥ奖瀛愬瘎瀛樺櫒锛圧tc_tr 鍜?rtc_dr锛変腑鍔犺浇鍒濆鏃堕棿鍜屾棩鏈熷€硷紝鐒跺悗閫氳繃 rtc_cr

聽 聽 聽 聽 瀵勫瓨鍣ㄤ腑鐨?/p>

fmt

浣嶉厤缃椂闂存牸寮忥紙

12

鎴?/p>

24

灏忔椂鍒讹級銆?

閫氳繃娓呴浂 init 浣嶉€€鍑哄垵濮嬪寲妯″紡銆傞殢鍚庯紝鑷姩鍔犺浇瀹為檯鏃ュ巻璁℃暟鍣ㄥ€硷紝鍦?4 涓?rtcclk

聽 聽 聽 聽 鏃堕挓鍛ㄦ湡鍚庨噸鏂板紑濮嬭鏁般€?

褰撳垵濮嬪寲搴忓垪瀹屾垚涔嬪悗锛屾棩鍘嗗紑濮嬭鏁般€?/p>

7.3.4 澶忎护鏃?/p>

鍙€氳繃

rtc_cr

瀵勫瓨鍣ㄧ殑

sub1h

銆?/p>

add1h

鍜?/p>

bkp

浣嶇鐞嗗浠ゆ椂銆?鍒╃敤 sub1h

鎴?/p>

add1h

锛岃蒋浠跺彧闇€鍗曟鎿嶄綔渚垮彲鍦ㄦ棩鍘嗕腑鍑忓幓鎴栧鍔犱竴涓皬鏃讹紝鏃犻渶鎵ц鏁翠釜鍒濆鍖栨楠ゃ€?姝ゅ锛岃蒋浠惰繕鍙互浣跨敤 bkp

浣嶆潵璁板綍鏄惁鏇剧粡鎵ц杩囨鎿嶄綔銆?/p>

7.4 rtc 鐩稿叧瀵勫瓨鍣?/p>

7.4.1 rtc 鏃堕棿瀵勫瓨鍣紙rtc_tr锛?/p>

浣?31-24 淇濈暀

浣?23 淇濈暀锛屽繀椤讳繚鎸佸浣嶅€笺€?

浣?22 pm锛欰m/pm 绗﹀彿 (am/pm notation)

0

锛?/p>

am

鎴?/p>

24

灏忔椂鍒?

1

锛?/p>

pm

浣?21:20 ht[1:0]锛氬皬鏃剁殑鍗佷綅锛圔cd 鏍煎紡锛?hour tens in bcd format)

浣?16:16 hu[3:0]锛氬皬鏃剁殑涓綅锛圔cd 鏍煎紡锛?hour units in bcd format)

浣?15 淇濈暀锛屽繀椤讳繚鎸佸浣嶅€笺€?

浣?14:12 mnt[2:0]锛氬垎閽熺殑鍗佷綅锛圔cd 鏍煎紡锛?minute tens in bcd format)

浣?11:8 mnu[3:0]锛氬垎閽熺殑涓綅锛圔cd 鏍煎紡锛?minute units in bcd format)

浣?7 淇濈暀锛屽繀椤讳繚鎸佸浣嶅€笺€?

浣?6:4 st[2:0]锛氱鐨勫崄浣嶏紙bcd 鏍煎紡锛?second tens in bcd format)

浣?3:0 su[3:0]锛氱鐨勪釜浣嶏紙bcd 鏍煎紡锛?second units in bcd format)

7.4.2 rtc鏃ユ湡瀵勫瓨鍣紙rtc_dr锛?/p>

浣?31-24 淇濈暀

浣?23:20 yt[3:0]锛氬勾浠界殑鍗佷綅锛圔cd 鏍煎紡锛?year tens in bcd format)

浣?19:16 yu[3:0]锛氬勾浠界殑涓綅锛圔cd 鏍煎紡锛?year units in bcd format)

浣?15:13 wdu[2:0]锛氭槦鏈熷嚑鐨勪釜浣?(week day units)

000

锛氱姝?

001

锛氭槦鏈熶竴

...

111

锛氭槦鏈熸棩

浣?12 mt锛氭湀浠界殑鍗佷綅锛圔cd 鏍煎紡锛?month tens in bcd format)

浣?11:8 mu锛氭湀浠界殑涓綅锛圔cd 鏍煎紡锛?month units in bcd format)

浣?7:6 淇濈暀锛屽繀椤讳繚鎸佸浣嶅€笺€?

浣?5:4 dt[1:0]锛氭棩鏈熺殑鍗佷綅锛圔cd 鏍煎紡锛?date tens in bcd format)

浣?3:0 du[3:0]锛氭棩鏈熺殑涓綅锛圔cd 鏍煎紡锛?date units in bcd format)

7.4.3 rtc鎺у埗瀵勫瓨鍣?/p>

浣?31:24 淇濈暀锛屽繀椤讳繚鎸佸浣嶅€?/p>

浣?23 coe锛氭牎鍑嗚緭鍑轰娇鑳?(calibration output enable)

璇ヤ綅浣胯兘

rtc_calib

杈撳嚭

0

锛氱姝㈡牎鍑嗚緭鍑?

1

锛氫娇鑳芥牎鍑嗚緭鍑?/p>

浣?22:21 osel[1:0]锛氳緭鍑洪€夋嫨 (output selection)

杩欎簺浣嶇敤浜庨€夋嫨瑕佽繛鎺ュ埌

rtc_alarm

杈撳嚭鐨勬爣蹇?

00

锛氱姝㈣緭鍑?

01

锛氫娇鑳介椆閽?/p>

a

杈撳嚭

10

锛氫娇鑳介椆閽?/p>

b

杈撳嚭

11

锛氫娇鑳藉敜閱掕緭鍑?

浣?20 pol锛氳緭鍑烘瀬鎬?(output polarity)

璇ヤ綅鐢ㄤ簬閰嶇疆

rtc_alarm

杈撳嚭鐨勬瀬鎬?

0

锛氬綋

alraf/alrbf/wutf

缃?/p>

1

鏃讹紙鍙栧喅浜?/p>

osel[1:0]

锛夛紝璇ュ紩鑴氫负楂樼數骞?

1

锛氬綋

alraf/alrbf/wutf

缃?/p>

1

鏃讹紙鍙栧喅浜?/p>

osel[1:0]

锛夛紝璇ュ紩鑴氫负浣庣數骞?

浣?19 cosel锛氭牎鍑嗚緭鍑洪€夋嫨 (calibration output selection)

褰?/p>

coe=1

鏃讹紝璇ヤ綅鍙€夋嫨

rtc_calib

涓婅緭鍑虹殑淇″彿銆?

0

锛氭牎鍑嗚緭鍑轰负

512 hz

1

锛氭牎鍑嗚緭鍑轰负

1 hz

鍦?/p>

rtcclk

涓?/p>

32.768 khz

涓旈鍒嗛鍣ㄤ负鍏堕粯璁ゅ€硷紙

prediv_a=127

涓?/p>

prediv_s=255

锛?

鐨勬潯浠朵笅锛岃繖浜涢鐜囨湁鏁堛€?/p>

浣?18 bkp锛氬浠?(backup)

鐢ㄦ埛鍙姝や綅鎵ц鍐欐搷浣滀互璁板綍鏄惁宸插澶忎护鏃惰繘琛屾洿鏀广€?

浣?17 sub1h锛氬噺灏?1 灏忔椂锛堝啲瀛f椂闂存洿鏀癸級(subtract 1 hour (winter time change))

褰撹浣嶅湪鍒濆鍖栨ā寮忎互澶栫殑妯″紡涓嬬疆

1

鏃讹紝濡傛灉褰撳墠灏忔椂涓嶆槸

0

锛屽垯鏃ュ巻鏃堕棿灏嗗噺灏?/p>

1

灏?

鏃躲€傛浣嶅缁堣涓?/p>

0

銆?

褰撳墠灏忔椂涓?/p>

0

鏃讹紝灏嗘浣嶇疆

1

娌℃湁浠讳綍浣滅敤銆?

0

锛氭棤浣滅敤銆?

1

锛氬皢褰撳墠鏃堕棿鍑忓皯

1

灏忔椂銆傝繖鍙敤浜庡啲瀛f椂闂存洿鏀广€?/p>

浣?16 add1h锛氬鍔?1 灏忔椂锛堝瀛f椂闂存洿鏀癸級(add 1 hour (summer time change))

褰撹浣嶅湪鍒濆鍖栨ā寮忎互澶栫殑妯″紡涓嬬疆

1

鏃讹紝鏃ュ巻鏃堕棿灏嗗鍔?/p>

1

灏忔椂銆傛浣嶅缁堣涓?/p>

0

銆?

0

锛氭棤浣滅敤銆?

1

锛氬皢褰撳墠鏃堕棿澧炲姞

1

灏忔椂銆傝繖鍙敤浜庡瀛f椂闂存洿鏀?

浣?15 tsie锛氭椂闂存埑涓柇浣胯兘 (timestamp interrupt enable)

0

锛氱姝㈡椂闂存埑涓柇

1

锛氫娇鑳芥椂闂存埑涓柇

浣?14 wutie锛氫娇鑳藉敜閱掑畾鏃跺櫒浣胯兘 (wakeup timer interrupt enable)

0

锛氱姝㈠敜閱掑畾鏃跺櫒涓柇

1

锛氫娇鑳藉敜閱掑畾鏃跺櫒涓柇

浣?13 alrbie锛氶椆閽?b 涓柇浣胯兘 (alarm b interrupt enable)

0

锛氶椆閽?/p>

b

涓柇绂佹

1

锛氶椆閽?/p>

b

涓柇浣胯兘

浣?12 alraie锛氶椆閽?a 涓柇浣胯兘 (alarm a interrupt enable)

0

锛氱姝㈤椆閽?/p>

a

涓柇

1

锛氫娇鑳介椆閽?/p>

a

涓柇

浣?11 tse锛氭椂闂存埑浣胯兘 (time stamp enable)

0

锛氱姝㈡椂闂存埑

1

锛氫娇鑳芥椂闂存埑

浣?10 wute锛氬敜閱掑畾鏃跺櫒浣胯兘 (wakeup timer enable)

0

锛氱姝㈠敜閱掑畾鏃跺櫒

1

锛氫娇鑳藉敜閱掑畾鏃跺櫒

浣?9 alrbe锛氶椆閽?b 浣胯兘 (alarm b enable)

0

锛氱姝㈤椆閽?/p>

b

1

锛氫娇鑳介椆閽?/p>

b

浣?8 alrae锛氶椆閽?a 浣胯兘 (alarm a enable)

0

锛氱姝㈤椆閽?/p>

a

1

锛氫娇鑳介椆閽?/p>

a

浣?7 dce锛氱矖鐣ユ暟瀛楁牎鍑嗕娇鑳?(coarse digital calibration enable)

0

锛氱姝㈡暟瀛楁牎鍑?

1

锛氫娇鑳芥暟瀛楁牎鍑?

prediv_a

蹇呴』澶т簬鎴栫瓑浜?/p>

6

浣?6 fmt锛氬皬鏃舵牸寮?(hour format)

0

锛?/p>

24

灏忔椂

/

澶╂牸寮?

1

锛?/p>

am/pm

灏忔椂鏍煎紡

浣?5 bypshad锛氭梺璺奖瀛愬瘎瀛樺櫒 (bypass the shadow registers)

0

锛氭棩鍘嗗€硷紙浠?/p>

rtc_ssr

銆?/p>

rtc_tr

鍜?/p>

rtc_dr

璇诲彇鏃讹級鍙栬嚜褰卞瓙瀵勫瓨鍣紝璇ュ奖瀛愬瘎瀛樺櫒

姣忎袱涓?/p>

rtcclk

鍛ㄦ湡鏇存柊涓€娆°€?

1

锛氭棩鍘嗗€硷紙浠?/p>

rtc_ssr

銆?/p>

rtc_tr

鍜?/p>

rtc_dr

璇诲彇鏃讹級鐩存帴鍙栬嚜鏃ュ巻璁℃暟鍣ㄣ€?

娉ㄦ剰锛氬鏋?/p>

apb1

鏃堕挓鐨勯鐜囦綆浜?/p>

7

鍊嶇殑

rtcclk

棰戠巼锛屽垯蹇呴』灏?/p>

bypshad

缃€?/p>

1

鈥?/p>

浣?4 refckon锛氬弬鑰冩椂閽熸娴嬩娇鑳斤紙50 hz 鎴?60 hz锛?reference clock detection enable (50 or

60 hz))

0

锛氱姝㈠弬鑰冩椂閽熸娴?

1

锛氫娇鑳藉弬鑰冩椂閽熸娴?

娉ㄦ剰锛?/p>

prediv_s

蹇呴』涓?/p>

0x00ff

銆?

浣?3 tsedge锛氭椂闂存埑浜嬩欢鏈夋晥杈规部 (timestamp event active edge)

0

锛?/p>

timestamp

涓婂崌娌跨敓鎴愭椂闂存埑浜嬩欢

1

锛?/p>

timestamp

涓嬮檷娌跨敓鎴愭椂闂存埑浜嬩欢

tsedge

鍙戠敓鏇存敼鏃讹紝蹇呴』澶嶄綅

tse

浠ラ伩鍏嶅皢

tsf

鎰忓缃?/p>

1

浣?2:0 wucksel[2:0]锛氬敜閱掓椂閽熼€夋嫨 (wakeup clock selection)

000

锛氶€夋嫨

rtc/16

鏃堕挓

001

锛氶€夋嫨

rtc/8

鏃堕挓

010

锛氶€夋嫨

rtc/4

鏃堕挓

011

锛氶€夋嫨

rtc/2

鏃堕挓

10x

锛氶€夋嫨

ck_spre

鏃堕挓锛堥€氬父涓?/p>

1 hz

锛?

11x

锛氶€夋嫨

ck_spre

鏃堕挓锛堥€氬父涓?/p>

1 hz

锛夊苟灏?/p>

wut

璁℃暟鍣ㄥ€煎鍔?/p>

2

16

锛堣涓嬮潰鐨勬敞閲婏級

7.4.4 rtc鍒濆鍖栧拰鐘舵€佸瘎瀛樺櫒锛圧tc_isr锛?/p>

聽浣?31:17 淇濈暀

浣?16 recalpf锛氶噸鏂版牎鍑嗘寕璧锋爣蹇?(recalibration pending flag)

褰撹蒋浠跺

rtc_calr

瀵勫瓨鍣ㄦ墽琛屽啓鎿嶄綔鏃讹紝

recalpf

鐘舵€佹爣蹇楀皢鑷姩缃€?/p>

1

鈥濓紝鎸囩ず

rtc_calr

瀵勫瓨鍣ㄥ凡灞忚斀銆傚綋閲囩敤鏂扮殑鏍″噯璁剧疆鏃讹紝璇ヤ綅鎭㈠涓衡€?/p>

0

鈥濄€傝鍙傝

鍔ㄦ€侀噸鏍″噯

涓€鑺傘€?

浣?15 淇濈暀锛屽繀椤讳繚鎸佸浣嶅€笺€?

浣?14 tamp2f锛歍amper2 妫€娴嬫爣蹇?(tamper2 detection flag)

鍦ㄥ叆渚佃緭鍏?/p>

2

涓婃娴嬪埌鍏ヤ镜妫€娴嬩簨浠舵椂锛岀敱纭欢灏嗘鏍囧織缃?/p>

1

銆?

璇ユ爣蹇楃敱杞欢鍐欓浂娓呴櫎銆?

浣?13 tamp1f锛氬叆渚垫娴嬫爣蹇?(tamper detection flag)

褰撴娴嬪埌鍏ヤ镜妫€娴嬩簨浠舵椂锛岀敱纭欢灏嗘鏍囧織缃?/p>

1

銆?

璇ユ爣蹇楃敱杞欢鍐欓浂娓呴櫎銆?

浣?12 tsovf锛氭椂闂存埑婧㈠嚭鏍囧織 (timestamp overflow flag)

褰撳湪

tsf

宸茬疆

1

鐨勬儏鍐典笅鍙戠敓鏃堕棿鎴充簨浠舵椂锛岀敱纭欢灏嗘鏍囧織缃?/p>

1

銆?

璇ユ爣蹇楃敱杞欢鍐欓浂娓呴櫎銆傚缓璁粎鍦?/p>

tsf

浣嶆竻闆朵箣鍚庡啀妫€鏌ュ苟娓呴浂

tsovf

浣嶃€傚惁鍒欙紝濡傛灉鏃?

闂存埑浜嬩欢鎭板ソ鍦ㄦ竻闆?/p>

tsf

浣嶄箣鍓嶅垰鍒氬彂鐢燂紝鍒欐孩鍑轰簨浠跺彲鑳戒細琚紡鎺夈€?

浣?11 tsf锛氭椂闂存埑鏍囧織 (timestamp flag)

鍙戠敓鏃堕棿鎴充簨浠舵椂锛岀敱纭欢灏嗘鏍囧織缃?/p>

1

銆?

璇ユ爣蹇楃敱杞欢鍐欓浂娓呴櫎銆?

浣?10 wutf锛氬敜閱掑畾鏃跺櫒鏍囧織 (wakeup timer flag)

褰撳敜閱掕嚜鍔ㄩ噸杞借鏁板櫒璁℃暟鍒?/p>

0

鏃讹紝鐢辩‖浠跺皢姝ゆ爣蹇楃疆

1

銆?

璇ユ爣蹇楃敱杞欢鍐欓浂娓呴櫎銆?

杞欢蹇呴』鍦?/p>

wutf

鍐嶆缃?/p>

1

鐨?/p>

1.5

涓?/p>

rtcclk

鍛ㄦ湡涔嬪墠灏嗚鏍囧織娓呴浂銆?/p>

浣?9 alrbf锛氶椆閽?b 鏍囧織 (alarm b flag)

褰撴椂闂?/p>

/

鏃ユ湡瀵勫瓨鍣紙

rtc_tr

鍜?/p>

rtc_dr

锛変笌闂归挓

b

瀵勫瓨鍣?/p>

(rtc_alrmbr)

鍖归厤鏃讹紝鐢?

纭欢灏嗚鏍囧織缃?/p>

1

銆?

璇ユ爣蹇楃敱杞欢鍐欓浂娓呴櫎銆?

浣?8 alraf锛氶椆閽?a 鏍囧織 (alarm a flag)

褰撴椂闂?/p>

/

鏃ユ湡瀵勫瓨鍣紙

rtc_tr

鍜?/p>

rtc_dr

锛変笌闂归挓

a

瀵勫瓨鍣?/p>

(rtc_alrmar)

鍖归厤鏃讹紝鐢?

纭欢灏嗚鏍囧織缃?/p>

1

銆?

璇ユ爣蹇楃敱杞欢鍐欓浂娓呴櫎銆?/p>

浣?7 init锛氬垵濮嬪寲妯″紡 (initialization mode)

0

锛氳嚜鐢辫繍琛屾ā寮忋€?

1

锛氬垵濮嬪寲妯″紡锛岀敤浜庣紪绋嬫椂闂村拰鏃ユ湡瀵勫瓨鍣紙

rtc_tr

鍜?/p>

rtc_dr

锛変互鍙婇鍒嗛鍣ㄥ瘎瀛樺櫒

(rtc_prer)

銆傝鏁板櫒鍋滄璁℃暟锛屽綋

init

琚浣嶅悗锛岃鏁板櫒浠庢柊鍊煎紑濮嬭鏁般€?

浣?6 initf锛氬垵濮嬪寲鏍囧織 (initialization flag)

褰撴浣嶇疆

1

鏃讹紝

rtc

澶勪簬鍒濆鍖栫姸鎬侊紝姝ゆ椂鍙洿鏂颁簨浠躲€佹棩鏈熷拰棰勫垎棰戝櫒瀵勫瓨鍣ㄣ€?

0

锛氫笉鍏佽鏇存柊鏃ュ巻瀵勫瓨鍣ㄣ€?

1

锛氬厑璁告洿鏂版棩鍘嗗瘎瀛樺櫒銆?

浣?5 rsf锛氬瘎瀛樺櫒鍚屾鏍囧織 (registers synchronization flag)

姣忔灏嗘棩鍘嗗瘎瀛樺櫒鐨勫€煎鍒跺埌褰卞瓙瀵勫瓨鍣紙

rtc_ssrx

銆?/p>

rtc_trx

鍜?/p>

rtc_drx

锛夋椂锛岄兘

浼氱敱纭欢灏嗘浣嶇疆

1

銆傚湪鍒濆鍖栨ā寮忎笅銆佸钩绉绘搷浣滄寕璧锋椂

(shpf=1)

鎴栧湪鏃佽矾褰卞瓙瀵勫瓨鍣ㄦā

寮?/p>

(bypshad=1)

涓嬶紝璇ヤ綅鐢辩‖浠舵竻闆躲€傝浣嶈繕鍙敱杞欢娓呴浂銆?

0

锛氭棩鍘嗗奖瀛愬瘎瀛樺櫒灏氭湭鍚屾

1

锛氭棩鍘嗗奖瀛愬瘎瀛樺櫒宸插悓姝?

浣?4 inits锛氬垵濮嬪寲鐘舵€佹爣蹇?(initialization status flag)

褰撴棩鍘嗗勾浠藉瓧娈典笉涓?/p>

0

鏃讹紙涓婄數澶嶄綅鐘舵€侊級锛岀敱纭欢灏嗚浣嶇疆

1

銆?

0

锛氭棩鍘嗗皻鏈垵濮嬪寲

1

锛氭棩鍘嗗凡缁忓垵濮嬪寲

浣?3 shpf锛氬钩绉绘搷浣滄寕璧?(shift operation pending)

0

锛氭病鏈夊钩绉绘搷浣滄寕璧?

1

锛氭煇涓钩绉绘搷浣滄寕璧?

鍙閫氳繃瀵?/p>

rtc_shiftr

瀵勫瓨鍣ㄦ墽琛屽啓鎿嶄綔鏉ュ惎鍔ㄥ钩绉绘搷浣滐紝姝ゆ爣蹇椾究鐢辩‖浠剁疆

1

銆傛墽琛屽畬

鐩稿簲鐨勫钩绉绘搷浣滃悗锛屾鏍囧織鐢辩‖浠舵竻闆躲€傚

shpf

鎵ц鍐欏叆鎿嶄綔涓嶈捣浣滅敤銆?

浣?2 wutwf锛氬敜閱掑畾鏃跺櫒鍐欐爣蹇?(wakeup timer write flag)

鍦?/p>

rtc_cr

瀵勫瓨鍣ㄤ腑鐨?/p>

wute

浣嶇疆

0

鍚庯紝褰撳敜閱掑畾鏃跺櫒鍊煎彲鏇存敼鏃讹紝鐢辩‖浠跺皢璇ヤ綅缃?/p>

1

銆?

0

锛氫笉鍏佽鏇存柊鍞ら啋瀹氭椂鍣ㄩ厤缃?

1

锛氬厑璁告洿鏂板敜閱掑畾鏃跺櫒閰嶇疆

浣?1 alrbwf锛氶椆閽?b 鍐欐爣蹇?(alarm b write flag)

鍦?/p>

rtc_cr

瀵勫瓨鍣ㄤ腑鐨?/p>

alrbie

浣嶇疆

0

涔嬪悗锛屽綋闂归挓

b

鐨勫€煎彲鏇存敼鏃讹紝鐢辩‖浠跺皢璇ヤ綅缃?/p>

1

銆?

璇ヤ綅鍦ㄥ垵濮嬪寲妯″紡涓嬬敱纭欢娓呴浂銆?

0

锛氫笉鍏佽鏇存柊闂归挓

b

1

锛氬厑璁告洿鏂伴椆閽?/p>

b

浣?0 alrawf锛氶椆閽?a 鍐欐爣蹇?(alarm a write flag)

鍦?/p>

rtc_cr

瀵勫瓨鍣ㄤ腑鐨?/p>

alrae

浣嶇疆

0

鍚庯紝褰撻椆閽?/p>

a

鐨勫€煎彲鏇存敼鏃讹紝鐢辩‖浠跺皢璇ヤ綅缃?/p>

1

銆?

璇ヤ綅鍦ㄥ垵濮嬪寲妯″紡涓嬬敱纭欢娓呴浂銆?

0

锛氫笉鍏佽鏇存柊闂归挓

a

1

锛氬厑璁告洿鏂伴椆閽?/p>

a

7.4.5聽 rtc棰勫垎棰戝瘎瀛樺櫒锛圱rc_prer锛?/p>

聽浣?31:24 淇濈暀

浣?23 淇濈暀锛屽繀椤讳繚鎸佸浣嶅€笺€?

浣?22:16 prediv_a[6:0]锛氬紓姝ラ鍒嗛绯绘暟 (asynchronous prescaler factor)

涓嬮潰鏄紓姝ュ垎棰戠郴鏁扮殑鍏紡锛?

ck_apre

棰戠巼

= rtcclk

棰戠巼

/(prediv_a 1)

娉ㄦ剰锛?/p>

prediv_a [6:0]= 000000

涓虹鐢ㄥ€笺€?

浣?15 淇濈暀锛屽繀椤讳繚鎸佸浣嶅€笺€?

浣?14:0 prediv_s[14:0]锛氬悓姝ラ鍒嗛绯绘暟 (synchronous prescaler factor)

涓嬮潰鏄悓姝ュ垎棰戠郴鏁扮殑鍏紡锛?

ck_spre

棰戠巼

= ck_apre

棰戠巼

/(prediv_s 1)

7.4.6 rtc鍞ら啋瀹氭椂鍣ㄥ瘎瀛樺櫒锛圧tc_wutr锛?/p>

聽浣?31:16 淇濈暀

浣?15:0 wut[15:0]锛氬敜閱掕嚜鍔ㄩ噸杞藉€间綅 (wakeup auto-reload value bit)

褰撲娇鑳藉敜閱掑畾鏃跺櫒鏃讹紙

wute

缃?/p>

1

锛夛紝姣?/p>

(wut[15:0] 1)

涓?/p>

ck_wut

鍛ㄦ湡灏?/p>

wutf

鏍囧織缃?/p>

1

涓€娆°€?/p>

ck_wut

鍛ㄦ湡閫氳繃

rtc_cr

瀵勫瓨鍣ㄧ殑

wucksel[2:0]

浣嶈繘琛岄€夋嫨銆?

褰?/p>

wucksel[2] = 1

鏃讹紝鍞ら啋瀹氭椂鍣ㄥ彉涓?/p>

17

浣嶏紝

wucksel[1]

绛夋晥涓?/p>

wut[16]

锛屽嵆瑕侀噸杞?

鍒板畾鏃跺櫒鐨勬渶楂樻湁鏁堜綅銆?

娉ㄦ剰锛?/p>

wutf

绗竴娆$疆

1

鍙戠敓鍦?/p>

wute

缃?/p>

1

涔嬪悗

(wut 1)

涓?/p>

ck_wut

鍛ㄦ湡銆傜姝㈠湪

wucksel[2:0]=011(rtcclk/2)

鏃跺皢

wut[15:0]

璁剧疆涓?/p>

0x0000

銆?/p>

7.4.7 rtc鏍″噯瀵勫瓨鍣紙rtc_calibr锛?/p>

浣?31:8 淇濈暀

浣?7 dcs锛氭暟瀛楁牎鍑嗙鍙?(digital calibration sign)

0

锛氭鏍″噯锛氬鍔犳棩鍘嗘洿鏂伴鐜?

1

锛氳礋鏍″噯锛氶檷浣庢棩鍘嗘洿鏂伴鐜?

浣?6:5 淇濈暀锛屽繀椤讳繚鎸佸浣嶅€笺€?

浣?4:0 dc[4:0]锛氭暟瀛楁牎鍑?(digital calibration)

dcs = 0

锛堟鏍″噯锛?

00000

锛?/p>

0 ppm

00001

锛?/p>

4 ppm

锛堣垗鍏ュ€硷級

00010

锛?/p>

8 ppm

锛堣垗鍏ュ€硷級

..

11111

锛?/p>

126 ppm

锛堣垗鍏ュ€硷級

dcs = 1

锛堣礋鏍″噯锛?

00000

锛?/p>

飥?/p>

0 ppm

00001

锛?/p>

飥?/p>

2 ppm

锛堣垗鍏ュ€硷級

00010

锛?/p>

飥?/p>

4 ppm

锛堣垗鍏ュ€硷級

..

11111

锛?/p>

飥?/p>

63 ppm

锛堣垗鍏ュ€硷級

7.4.8 rtc闂归挓a瀵勫瓨鍣紙rtc_alrmar锛?/p>

聽浣?31 msk4锛氶椆閽?a 鏃ユ湡鎺╃爜 (alarm a date mask)

0

锛氬鏋滄棩鏈?/p>

/

鏃ュ尮閰嶏紝鍒欓椆閽?/p>

a

缃?/p>

1

1

锛氬湪闂归挓

a

姣旇緝涓紝鏃ユ湡

/

鏃ユ棤鍏?

浣?30 wdsel锛氭槦鏈熷嚑閫夋嫨 (week day selection)

0

锛?/p>

du[3:0]

浠h〃鏃ユ湡鐨勪釜浣?

1

锛?/p>

du[3:0]

浠h〃鏄熸湡鍑犮€?/p>

dt[1:0]

涓烘棤鍏充綅銆?

浣?29:28 dt[1:0]锛氭棩鏈熺殑鍗佷綅锛圔cd 鏍煎紡锛?date tens in bcd format)銆?

浣?27:24 du[3:0]锛氭棩鏈熺殑涓綅鎴栨棩锛圔cd 鏍煎紡锛?date units or day in bcd format)銆?

浣?23 msk3锛氶椆閽?a 灏忔椂鎺╃爜 (alarm a hours mask)

0

锛氬鏋滃皬鏃跺尮閰嶏紝鍒欓椆閽?/p>

a

缃?/p>

1

1

锛氬湪闂归挓

a

姣旇緝涓紝灏忔椂鏃犲叧

浣?22 pm锛欰m/pm 绗﹀彿 (am/pm notation)

0

锛?/p>

am

鎴?/p>

24

灏忔椂鍒?

1

锛?/p>

pm

浣?21:20 ht[1:0]锛氬皬鏃剁殑鍗佷綅锛圔cd 鏍煎紡锛?hour tens in bcd format)銆?

浣?19:16 hu[3:0]锛氬皬鏃剁殑涓綅锛圔cd 鏍煎紡锛?hour units in bcd format)銆?

浣?15 msk2锛氶椆閽?a 鍒嗛挓鎺╃爜 (alarm a minutes mask)

0

锛氬鏋滃垎閽熷尮閰嶏紝鍒欓椆閽?/p>

a

缃?/p>

1

1

锛氬湪闂归挓

a

姣旇緝涓紝鍒嗛挓鏃犲叧

浣?14:12 mnt[2:0]锛氬垎閽熺殑鍗佷綅锛圔cd 鏍煎紡锛?minute tens in bcd format)銆?

浣?11:8 mnu[3:0]锛氬垎閽熺殑涓綅锛圔cd 鏍煎紡锛?minute units in bcd format)銆?

浣?7 msk1锛氶椆閽?a 绉掓帺鐮?(alarm a seconds mask)

0

锛氬鏋滅鍖归厤锛屽垯闂归挓

a

缃?/p>

1

1

锛氬湪闂归挓

a

姣旇緝涓紝绉掓棤鍏?

浣?6:4 st[2:0]锛氱鐨勫崄浣嶏紙bcd 鏍煎紡锛?second tens in bcd format)銆?

浣?3:0 su[3:0]锛氱鐨勪釜浣嶏紙bcd 鏍煎紡锛?second units in bcd format)

7.4.9 rtc闂归挓b瀵勫瓨鍣紙rtc_alrmbr锛?/p>

聽浣?31 msk4锛氶椆閽?b 鏃ユ湡鎺╃爜 (alarm b date mask)

0

锛氬鏋滄棩鏈熷拰鏃ュ尮閰嶏紝鍒欓椆閽?/p>

b

缃?/p>

1

1

锛氬湪闂归挓

b

姣旇緝涓紝鏃ユ湡鍜屾棩鏃犲叧

浣?30 wdsel锛氭槦鏈熷嚑閫夋嫨 (week day selection)

0

锛?/p>

du[3:0]

浠h〃鏃ユ湡鐨勪釜浣嶃€?

1

锛?/p>

du[3:0]

浠h〃鏄熸湡鍑犮€?/p>

dt[1:0]

涓烘棤鍏充綅銆?

浣?29:28 dt[1:0]锛氭棩鏈熺殑鍗佷綅锛圔cd 鏍煎紡锛?date tens in bcd format)

浣?27:24 du[3:0]锛氭棩鏈熶釜浣嶆垨鏃ワ紙bcd 鏍煎紡锛?date units or day in bcd format)

浣?23 msk3锛氶椆閽?b 灏忔椂鎺╃爜 (alarm b hours mask)

0

锛氬鏋滃皬鏃跺尮閰嶏紝鍒欓椆閽?/p>

b

缃?/p>

1

1

锛氬湪闂归挓

b

姣旇緝涓紝灏忔椂鏃犲叧

浣?22 pm锛欰m/pm 绗﹀彿 (am/pm notation)

0

锛?/p>

am

鎴?/p>

24

灏忔椂鍒?

1

锛?/p>

pm

浣?21:20 ht[1:0]锛氬皬鏃剁殑鍗佷綅锛圔cd 鏍煎紡锛?hour tens in bcd format)

浣?19:16 hu[3:0]锛氬皬鏃剁殑涓綅锛圔cd 鏍煎紡锛?hour units in bcd format)

浣?15 msk2锛氶椆閽?b 鍒嗛挓鎺╃爜 (alarm b minutes mask)

0

锛氬鏋滃垎閽熷尮閰嶏紝鍒欓椆閽?/p>

b

缃?/p>

1

1

锛氬湪闂归挓

b

姣旇緝涓紝鍒嗛挓鏃犲叧

浣?14:12 mnt[2:0]锛氬垎閽熺殑鍗佷綅锛圔cd 鏍煎紡锛?minute tens in bcd format)

浣?11:8 mnu[3:0]锛氬垎閽熺殑涓綅锛圔cd 鏍煎紡锛?minute units in bcd format)

浣?7 msk1锛氶椆閽?b 绉掓帺鐮?(alarm b seconds mask)

0

锛氬鏋滅鍖归厤锛屽垯闂归挓

b

缃?/p>

1

1

锛氬湪闂归挓

b

姣旇緝涓紝绉掓棤鍏?

浣?6:4 st[2:0]锛氱鐨勫崄浣嶏紙bcd 鏍煎紡锛?second tens in bcd format)

浣?3:0 su[3:0]锛氱鐨勪釜浣嶏紙bcd 鏍煎紡锛?second units in bcd format)

7.4.10 rtc鍐欎繚鎶ゅ瘎瀛樺櫒锛圧tc_wpr锛?/p>

聽涓婄數鍚庯紝鎵€鏈?rtc 瀵勫瓨鍣ㄩ兘鍙楀埌鍐欎繚鎶わ紙 rtc_isr[13:8]銆?rtc_tafcr 鍜?rtc_bkpxr 闄ゅ锛夛紝蹇呴』渚濇鍐欏叆锛?0xca銆?0x53 涓ゅ叧閿瓧鍒?rtc_wpr 瀵勫瓨 鍣紝鎵嶅彲浠ヨв閿併€?/p>

浣?31:8 淇濈暀锛屽繀椤讳繚鎸佸浣嶅€笺€?

浣?7:0 key锛氬啓淇濇姢鍏抽敭瀛?(write protection key)

鍙€氳繃杞欢瀵硅瀛楄妭鎵ц鍐欐搷浣溿€?

璇诲彇璇ュ瓧鑺傛椂锛屽缁堣繑鍥?/p>

0x00

銆?/p>

7.5 瀹炰緥浠g爜锛堝垵濮嬪寲鏃堕棿鍜屾棩鏈燂級

#include "rtc.h" // device header

#include "stdio.h"

void rtc_time_init(u16 year, u16 month, u16 day,u16 hour,u16 minute,u16 second,u16 weekday)

{

rtc_inittypedef rtc;

rtc_timetypedef rtctime;

rtc_datetypedef rtcdate;

rcc_apb1periphclockcmd(rcc_apb1periph_pwr,enable); //pwr鎺у埗鍐欎繚鎶ょ殑鐢垫簮/澶囦唤鍖虹數婧?/p>

pwr_backupaccesscmd(enable); //浣胯兘pwr澶囦唤鍩熺數婧?/p>

pwr_backupregulatorcmd(enable); //浣胯兘rtc澶囦唤瀵勫瓨鍣?/p>

//1銆侀€夋嫨rtc鏃堕挓婧?/p>

rcc_rtcclkconfig(rcc_rtcclksource_lse); //rtc閫夋嫨lse澶栭儴浣庨€熸椂閽?/p>

rcc_rtcclkcmd(enable); //浣胯兘rtc鏃堕挓

rcc_lseconfig(rcc_lse_on); //鎵撳紑lse鏃堕挓

while(!(rcc_getflagstatus(rcc_flag_lserdy)==set)); //绛夊緟lse鏃堕挓绮惧瘑鏍″噯瀹屾垚

while(!(rtc_waitforsynchro() == success)); //绛夊緟lse鏃堕挓鍜孯tc鍚屾瀹屾垚

rtc_writeprotectioncmd(disable); //鍐橠isable锛屾槸澶辫兘鍐欎繚鎶ゅ姛鑳?

while(!(rtc_enterinitmode() == success) ); //绛夊緟杩涘叆鍒濆鍖栨ā寮忓畬鎴?/p>

//鍒濆鍖朢tc

rtc.rtc_asynchprediv= 127; //寮傛,瀵勫瓨鍣ㄥ凡缁?1

rtc.rtc_hourformat=rtc_hourformat_24; //24灏忔椂鍒?/p>

rtc.rtc_synchprediv=255; //鍚屾锛屽瘎瀛樺櫒宸茬粡 1

rtc_init(&rtc); //鍒濆鍖朢tc

//璁剧疆鏃堕棿

rtctime.rtc_hours=hour; //鏃?/p>

rtctime.rtc_minutes=minute; //鍒?/p>

rtctime.rtc_seconds=second; //绉?/p>

rtc_settime(rtc_format_bin, &rtctime);

//璁剧疆鏃ユ湡

rtcdate.rtc_year=year; //骞?/p>

rtcdate.rtc_month=month; //鏈?/p>

rtcdate.rtc_date=day; //鏃?/p>

rtcdate.rtc_weekday=weekday; //鏄熸湡

rtc_setdate(rtc_format_bin, &rtcdate);

rtc_writeprotectioncmd(enable); //寮€鍚啓淇濇姢鍔熻兘

}

7.6 浠g爜瀹炵幇锛圧tc澶囦唤鍖?-澶嶄綅涓嶄慨鏀规椂闂达級

#include "rtc.h" // device header

#include "stdio.h"

void rtc_time_init(u16 year, u16 month, u16 day,u16 hour,u16 minute,u16 second,u16 weekday)

{

rtc_inittypedef rtc;

rtc_timetypedef rtctime;

rtc_datetypedef rtcdate;

rcc_apb1periphclockcmd(rcc_apb1periph_pwr,enable); //pwr鎺у埗鍐欎繚鎶ょ殑鐢垫簮/澶囦唤鍖虹數婧?/p>

pwr_backupaccesscmd(enable); //浣胯兘pwr澶囦唤鍩熺數婧?/p>

pwr_backupregulatorcmd(enable); //浣胯兘rtc澶囦唤瀵勫瓨鍣?/p>

//1銆侀€夋嫨rtc鏃堕挓婧愪负lse

rcc_rtcclkconfig(rcc_rtcclksource_lse); //rtc閫夋嫨lse澶栭儴浣庨€熸椂閽?/p>

rcc_rtcclkcmd(enable); //浣胯兘rtc鏃堕挓

//2銆佹墦寮€lse鏃堕挓

rcc_lseconfig(rcc_lse_on);

while(!(rcc_getflagstatus(rcc_flag_lserdy)==set)); //绛夊緟lse鏃堕挓鏍″噯瀹屾垚

while(!(rtc_waitforsynchro() == success)); //绛夊緟lse鏃堕挓鍜孯tc杩涜鍚屾瀹屾垚

rtc_writeprotectioncmd(disable); //鍐橠isable锛屾槸澶辫兘鍐欎繚鎶ゅ姛鑳?

if(rtc_readbackupregister(rtc_bkp_dr0)!=0xaa) //璇诲浠藉尯锛屽垽鏂槸鍚﹀垵濮嬪寲杩?/p>

{

while(!(rtc_enterinitmode() == success) ); //浣胯兘鍒濆鍖栦箣鍓嶏紝蹇呴』鍏堝叧闂啓淇濇姢锛岀瓑寰呰繘鍏ュ垵濮嬪寲妯″紡瀹屾垚

//鍒濆鍖朢tc

rtc.rtc_asynchprediv= 127; //寮傛,瀵勫瓨鍣ㄥ凡缁?1

rtc.rtc_hourformat=rtc_hourformat_24; //24灏忔椂鍒?/p>

rtc.rtc_synchprediv=255; //鍚屾锛屽瘎瀛樺櫒宸茬粡 1

rtc_init(&rtc); //鍒濆鍖朢tc

//璁剧疆鏃堕棿

rtctime.rtc_hours=hour; //鏃?/p>

rtctime.rtc_minutes=minute; //鍒?/p>

rtctime.rtc_seconds=second; //绉?/p>

rtc_settime(rtc_format_bin, &rtctime);

//璁剧疆鏃ユ湡

rtcdate.rtc_year=year; //骞?/p>

rtcdate.rtc_month=month; //鏈?/p>

rtcdate.rtc_date=day; //鏃?/p>

rtcdate.rtc_weekday=weekday; //鏄熸湡

rtc_setdate(rtc_format_bin, &rtcdate);

rtc_writebackupregister(rtc_bkp_dr0, 0xaa); //鍐欏叆澶囦唤鍖?xaa锛岃褰曞凡缁忓垵濮嬪寲鍖栬繃涓€娆′簡

}

rtc_writeprotectioncmd(enable); //寮€鍚啓淇濇姢鍔熻兘

}

澶嶄綅鍚庢椂闂存病鏈夋敼鍙樼殑锛?/p>

7.7 浠g爜瀹炵幇锛圠cd鏄剧ず 鍔ㄦ€佷慨鏀筊tc鏃堕棿鏃ユ湡锛?/p>

#include "rtc.h" // device header

#include "stdio.h"

void rtc_time_init(u16 year, u16 month, u16 day,u16 hour,u16 minute,u16 second,u16 weekday)

{

rtc_inittypedef rtc;

rtc_timetypedef rtctime;

rtc_datetypedef rtcdate;

rcc_apb1periphclockcmd(rcc_apb1periph_pwr,enable); //pwr鎺у埗鍐欎繚鎶ょ殑鐢垫簮/澶囦唤鍖虹數婧?/p>

pwr_backupaccesscmd(enable); //浣胯兘pwr澶囦唤鍩熺數婧?/p>

pwr_backupregulatorcmd(enable); //浣胯兘rtc澶囦唤瀵勫瓨鍣?/p>

//1銆侀€夋嫨rtc鏃堕挓婧愪负lse

rcc_rtcclkconfig(rcc_rtcclksource_lse); //rtc閫夋嫨lse澶栭儴浣庨€熸椂閽?/p>

rcc_rtcclkcmd(enable); //浣胯兘rtc鏃堕挓

//2銆佹墦寮€lse鏃堕挓

rcc_lseconfig(rcc_lse_on);

while(!(rcc_getflagstatus(rcc_flag_lserdy)==set)); //绛夊緟lse鏃堕挓鏍″噯瀹屾垚

while(!(rtc_waitforsynchro() == success)); //绛夊緟lse鏃堕挓鍜孯tc杩涜鍚屾瀹屾垚

rtc_writeprotectioncmd(disable); //鍐橠isable锛屾槸澶辫兘鍐欎繚鎶ゅ姛鑳?

if(rtc_readbackupregister(rtc_bkp_dr0)!=0xaa) //璇诲浠藉尯锛屽垽鏂槸鍚﹀垵濮嬪寲杩?/p>

{

while(!(rtc_enterinitmode() == success) ); //浣胯兘鍒濆鍖栦箣鍓嶏紝蹇呴』鍏堝叧闂啓淇濇姢锛岀瓑寰呰繘鍏ュ垵濮嬪寲妯″紡瀹屾垚

//鍒濆鍖朢tc

rtc.rtc_asynchprediv= 127; //寮傛,瀵勫瓨鍣ㄥ凡缁?1

rtc.rtc_hourformat=rtc_hourformat_24; //24灏忔椂鍒?/p>

rtc.rtc_synchprediv=255; //鍚屾锛屽瘎瀛樺櫒宸茬粡 1

rtc_init(&rtc); //鍒濆鍖朢tc

//璁剧疆鏃堕棿

rtctime.rtc_hours=hour; //鏃?/p>

rtctime.rtc_minutes=minute; //鍒?/p>

rtctime.rtc_seconds=second; //绉?/p>

rtc_settime(rtc_format_bin, &rtctime);

//璁剧疆鏃ユ湡

rtcdate.rtc_year=year; //骞?/p>

rtcdate.rtc_month=month; //鏈?/p>

rtcdate.rtc_date=day; //鏃?/p>

rtcdate.rtc_weekday=weekday; //鏄熸湡

rtc_setdate(rtc_format_bin, &rtcdate);

rtc_writebackupregister(rtc_bkp_dr0, 0xaa); //鍐欏叆澶囦唤鍖?xaa锛岃褰曞凡缁忓垵濮嬪寲鍖栬繃涓€娆′簡

}

rtc_writeprotectioncmd(enable); //寮€鍚啓淇濇姢鍔熻兘

}

void rtc_set_time(u16 hour,u16 minute,u16 second)

{

rtc_timetypedef rtctime;

rtc_writeprotectioncmd(disable); //鍐橠isable锛屾槸澶辫兘鍐欎繚鎶ゅ姛鑳?

while(!(rtc_enterinitmode() == success) ); //浣胯兘鍒濆鍖栦箣鍓嶏紝蹇呴』鍏堝叧闂啓淇濇姢锛岀瓑寰呰繘鍏ュ垵濮嬪寲妯″紡瀹屾垚

//璁剧疆鏃堕棿

rtctime.rtc_hours=hour; //鏃?/p>

rtctime.rtc_minutes=minute; //鍒?/p>

rtctime.rtc_seconds=second; //绉?/p>

rtc_settime(rtc_format_bin, &rtctime);

rtc_writeprotectioncmd(enable); //寮€鍚啓淇濇姢鍔熻兘

}

void rtc_set_date(u16 year, u16 month, u16 day,u16 weekday)

{

rtc_datetypedef rtcdate;

rtc_writeprotectioncmd(disable); //鍐橠isable锛屾槸澶辫兘鍐欎繚鎶ゅ姛鑳?

while(!(rtc_enterinitmode() == success) ); //浣胯兘鍒濆鍖栦箣鍓嶏紝蹇呴』鍏堝叧闂啓淇濇姢锛岀瓑寰呰繘鍏ュ垵濮嬪寲妯″紡瀹屾垚

rtcdate.rtc_year=year; //骞?/p>

rtcdate.rtc_month=month; //鏈?/p>

rtcdate.rtc_date=day; //鏃?/p>

rtcdate.rtc_weekday=weekday; //鏄熸湡

rtc_setdate(rtc_format_bin, &rtcdate);

rtc_writeprotectioncmd(enable); //寮€鍚啓淇濇姢鍔熻兘

}

8 .鐪嬮棬鐙?/p>

8.1 鐪嬮棬鐙楃畝浠?/p>

姝ゅ櫒浠跺叿鏈変袱涓祵鍏ュ紡鐪嬮棬鐙楀璁撅紝鍏锋湁瀹夊叏鎬ч珮銆佸畾鏃跺噯纭強浣跨敤鐏垫椿鐨勪紭鐐广€備袱涓湅闂?鐙楀璁撅紙鐙珛鍜岀獥鍙o級鍧囧彲鐢ㄤ簬妫€娴嬪苟瑙e喅鐢辫蒋浠堕敊璇鑷寸殑鏁呴殰锛涘綋璁℃暟鍣ㄨ揪鍒扮粰瀹氱殑瓒?鏃跺€兼椂锛岃е鍙戜竴涓腑鏂紙浠呴€傜敤浜庣獥鍙e瀷鐪嬮棬鐙楋級鎴栦骇鐢熺郴缁熷浣嶃€傛敞鎰忥細鐙珛鐪嬮棬鐙楁病鏈変腑鏂紝浣嗘槸鍙互瑙﹀彂涓柇鏈嶅姟鍑芥暟銆?/p>

8.2 鐪嬮棬鐙楃殑浣滅敤

聽 鐪嬮棬鐙楋紝鏈川涓婃槸涓€涓畾鏃跺櫒锛岃繖涓畾鏃跺櫒鏈変竴涓緭鍑虹锛屽彲浠ヨ緭鍑哄浣嶄俊鍙枫€備竴鑸儏鍐典笅锛岀湅闂ㄧ嫍瀹氭椂鍣ㄦ槸缁欎竴涓瘮杈冨ぇ鐨勫垵濮嬪€硷紝鐒跺悗浠庤繖涓€煎紑濮嬮€掑噺鎿嶄綔锛屽綋鍑忓埌0鏃跺€欙紝灏变細鍙戝嚭澶嶄綅淇″彿锛屽浣岰pu銆傛垜浠彲浠ュ湪绋嬪簭姝e父杩愯鐨勫湴鏂瑰懆鏈熸€х殑閲嶇疆璁℃暟鍣ㄥ€硷紝鍙鑳藉湪璁℃暟鍣ㄥ噺鍒?鍓嶆妸鍊奸噸鏂拌缃紝杩欎釜鍔ㄤ綔绉颁负鍠傜嫍锛岃繖鏍峰氨涓嶄細澶嶄綅浜嗐€備絾鏄紝濡傛灉绋嬪簭鏈塀ug,鏈夊彲鑳藉湪鏌愪簺鏃跺€欑▼搴忚劚绂绘甯哥殑杩愯璺嚎锛岀о涓虹▼搴忚窇椋炰簡锛岃繖鏍凤紝瀹氭椂鍣ㄧ敱浜庡緱涓嶅埌閲嶆柊鍒濆鍖栵紝鏈夋満浼氶€掑噺鍒?锛屼骇鐢熷浣嶄俊鍙枫€傚浣嶅悗锛岀▼搴忎粠澶村紑濮嬫墽琛屻€傛墍浠ワ紝鐪嬮棬鐙楄捣鍒颁簡鐩戞帶cpu杩愯锛岄槻姝cu姝绘満鐨勪綔鐢ㄣ€?/p>

鎬荤粨锛氱湅闂ㄧ嫍璧峰埌浜嗙洃鎺pu杩愯锛岄槻姝cu姝绘満鐨勪綔鐢ㄣ€?/p>

鍘熺悊鍥?

8.3 鐪嬮棬鐙楃殑閫夋嫨 聽 聽聽聽

鐙珛鐪嬮棬鐙楃敤浜庣簿搴︿綆鐨勫満鍚堬紝绐楀彛鐪嬮棬鐙楃敤浜庣簿搴﹂珮鐨勫満鍚堛€?/p>

8.4 鐙珛鐪嬮棬鐙?/p>

8.4.1 鏃堕挓

聽8.4.2聽ls鏃堕挓

8.4.3 鐗规€?/p>

鈼?鑷敱杩愯閫掑噺璁℃暟鍣紱

鈼?鏃堕挓鐢辩嫭绔?rc 鎸崱鍣ㄦ彁渚涳紙鍙湪寰呮満鍜屽仠姝㈡ā寮忎笅杩愯锛夛紱

鈼?褰撻€掑噺璁℃暟鍣ㄥ€艰揪鍒?0x000 鏃朵骇鐢熷浣嶏紙濡傛灉鐪嬮棬鐙楀凡婵€娲伙級锛?/p>

8.4.4 棰勫垎棰?/p>

8.5 鐙珛鐪嬮棬鐙楀垵濮嬪寲聽

#include "iwdg.h" // device header

void iwdg_init(u16 pr,u16 rlr)

{

rcc_lsicmd(enable);

iwdg_writeaccesscmd(iwdg_writeaccess_enable); //鍏抽棴鍐欎繚鎶?/p>

iwdg_setprescaler(pr); //棰勫垎棰?/p>

iwdg_setreload(rlr); //閲嶈杞藉€?/p>

iwdg_enable(); //鍚姩鐙珛鐪嬮棬鐙?/p>

iwdg_reloadcounter(); //鍚姩涓€娆″杺鐙楋紝鍐欏叆0xaaaa锛岄噸瑁呰浇鐨勫€兼墠浼氳浼犻€掑埌璁¤鏁板櫒

}

8.6 绐楀彛鐪嬮棬鐙?/p>

8.6.1 鐗圭偣

绐楀彛鐪嬮棬鐙楀拰鐙珛鐪嬮棬鐙椾笉涓€鏍风殑鍦版柟鍦ㄤ簬瀹冨叿澶囦腑鏂紱

鍙紪绋嬬殑鑷敱杩愯閫掑噺璁℃暟鍣紱

澶嶄綅鏉′欢锛氬綋閫掑噺璁℃暟鍣ㄥ€煎皬浜?0x40 鏃跺浣嶏紙濡傛灉鐪嬮棬鐙楀凡婵€娲伙級锛涘湪绐楀彛涔嬪閲嶈浇閫掑噺璁℃暟鍣ㄦ椂澶嶄綅锛堝鏋滅湅闂ㄧ嫍宸叉縺娲伙級銆?/p>

涓柇瑙﹀彂鏉′欢锛氭彁鍓嶅敜閱掍腑鏂?(ewi)锛氬綋閫掑噺璁℃暟鍣ㄧ瓑浜?0x40 鏃惰е鍙戯紙濡傛灉宸蹭娇鑳戒笖鐪嬮棬鐙楀凡婵€娲伙級銆?/p>

8.6.2 鍘熺悊聽

闄ら潪閫掑噺璁℃暟鍣ㄧ殑鍊煎湪 t6 浣嶅彉鎴?0 鍓嶈鍒锋柊锛岀湅闂ㄧ嫍鐢佃矾鍦?杈惧埌棰勭疆鐨勬椂闂村懆鏈熸椂锛屼細浜х敓涓€涓?mcu 澶嶄綅銆傚鏋滃湪閫掑噺璁℃暟鍣ㄨ揪鍒扮獥鍙e瘎瀛樺櫒鍊间箣鍓?鍒锋柊鎺у埗瀵勫瓨鍣ㄤ腑鐨?7 浣嶉€掑噺璁℃暟鍣ㄥ€硷紝涔熶細浜х敓 mcu 澶嶄綅銆傝繖鎰忓懗鐫€蹇呴』鍦ㄩ檺瀹氱殑鏃堕棿 绐楀彛鍐呭埛鏂拌鏁板櫒銆?/p>

8.6.3聽 绐楀彛鐪嬮棬鐙楀垵濮嬪寲

鏃堕挓聽

浣跨敤鐨勫嚱鏁板垎棰懧犺缃獥鍙e€硷紱浣胯兘鐪嬮棬鐙椾腑鏂紱浣胯兘鐪嬮棬鐙楁椂锛岄渶瑕佽缃鏁板€硷紝浣嗘槸璁℃暟鍊间笉鑳藉ぇ浜庣獥鍙e€?锛涚▼搴忓垵濮嬪寲

鍦ㄤ腑鏂腑鍠傜嫍锛浡?/p>

8.6.4 婧愮爜绋嬪簭聽

#include "wwdg.h" // device header

#include "stdio.h"

int n;

void wwdg_init(u8 windowvalue,u8 counter)

{

nvic_inittypedef wwdg_nvic;

rcc_apb1periphclockcmd(rcc_apb1periph_wwdg, enable); //浣胯兘鏃堕挓

wwdg_setprescaler(wwdg_prescaler_8); //8鍒嗛 wwdg counter clock = (pclk1/4096)/8

wwdg_setwindowvalue(windowvalue); //璁剧疆绐楀彛鍊?/p>

wwdg_nvic.nvic_irqchannel = wwdg_irqn;

wwdg_nvic.nvic_irqchannelpreemptionpriority = 0; //鎶㈠崰涓?

wwdg_nvic.nvic_irqchannelsubpriority = 0;//鍝嶅簲涓?

wwdg_nvic.nvic_irqchannelcmd = enable;

nvic_init(&wwdg_nvic);

n=counter;

wwdg_enableit(); //浣胯兘绐楀彛鐪嬮棬鐙椾腑鏂?/p>

wwdg_enable(counter); //浣胯兘鐪嬮棬鐙楋紝璁剧疆璁℃暟鍊硷紝浼犻€掑ぇ浜?x40鐨勫€硷紝闃叉鍒濆鍖栧悗浜х敓涓€娆″浣?/p>

}

//绐楀彛鐪嬮棬鐙椾腑鏂?/p>

void wwdg_irqhandler(void)

{

wwdg_setcounter(n); //璁剧疆璁℃暟鍊硷紝鍠傜嫍

wwdg_clearflag(); //ewif锛?鎻愬墠鍞ら啋涓柇鏍囧織锛屾竻涓柇鏍囧織浣?

//printf("鍠傜嫍浜哱r\n"); //2-3ms

}

9. rs485

瀛︿範璇ュ唴瀹圭殑鐩殑锛氬浼氫娇鐢?85瀹炵幇涓€涓诲浠庣殑鏁版嵁閫氫俊鎺у埗

9.1 姒傚康

瀛︿細浣跨敤485瀹炵幇涓€涓诲浠庣殑鏁版嵁閫氫俊鎺у埗锛?/p>

9.2 鐗╃悊锛堢‖浠讹級鎺ュ彛鏍囧噯

鎸夌収鐢靛钩鍒嗙被鍙互鍒嗘垚ttl銆丷s232銆丷s422銆丷s485锛屼笅闈㈤€愪竴浠嬬粛锛?/p>

9.2.1 ttl鐢靛钩

楂樼數骞筹細2.4-5v锛?1鍗曠墖鏈哄伐浣滅數鍘嬫槸5v锛汭o鍙h緭鍑洪珮鐢靛钩灏辨槸5v锛?/p>

浣庣數骞筹細0~0.4v锛?/p>

鏁板瓧鐢佃矾涓紝鐢盩tl鐢靛瓙鍏冨櫒浠剁粍鎴愮數璺娇鐢ㄧ殑鐢靛钩銆傜數骞虫槸涓數鍘嬭寖鍥达紝瑙勫畾杈撳嚭楂樼數骞?2.4v,杈撳嚭浣庣數骞?0.4v銆傚湪瀹ゆ俯涓嬶紝涓€鑸緭鍑洪珮鐢靛钩鏄?.5v锛岃緭鍑轰綆鐢靛钩鏄?.2v銆傛渶灏忚緭鍏ラ珮鐢靛钩鍜屼綆鐢靛钩锛氳緭鍏ラ珮鐢靛钩>=2.0v锛岃緭鍏ヤ綆鐢靛钩<=0.8v锛屽櫔澹板闄愭槸0.4v銆?/p>

聽鎴戜滑涔嬪墠浣跨敤鐨刄sart锛圲art锛夛紝榛樿涓篢tl鐢靛钩锛屾垜浠崟鐗囨満鐨処/o杈撳叆杈撳嚭鐨勭數骞虫槸鍜孴tl鍏煎锛沀sart锛圲art锛夋寜3.3v鏉ヨ锛屾甯?绫充箣鍐呫€?/p>

9.2.2 rs232

楂樼數骞筹細鐢靛钩涓洪€昏緫鈥?1鈥濇椂锛?-3v锝?15v锛?/p>

浣庣數骞筹細鐢靛钩涓洪€昏緫鈥?0鈥濇椂锛? 3v锝?15v锛?/p>

浼犺緭璺濈锛?0鑻卞昂锛屼竴鑻卞昂=0.38绫筹紱50鑻卞昂=15.24绫筹紱

浼犺緭閫熷害锛?0kbps,涓€鏀朵竴鍙戞ā寮?/p>

9.2.3 rs422聽

鏍囧噯锛?鏀?0鍙戯紱浼犺緭璺濈4000鑻卞昂=1219.2绫?/p>

9.2.4 rs485

rs-485 鏍囧噯鏄负寮ヨˉ rs-232 閫氫俊璺濈鐭€侀€熺巼浣庣瓑缂虹偣鑰屼骇鐢熺殑銆?rs-485 鏍囧噯鍙 瀹氫簡骞宠 鍙戦€佸櫒鍜屾帴鏀跺櫒鐨勭數鐗规€э紝鑰屾病鏈夎瀹氭帴鎻掍欢銆佷紶杈撶數缂嗗拰搴旂敤灞傞€氫俊鍗忚銆?/p>

鍙戦€佸櫒鍜屾帴鏀跺櫒锛?/p>

楂樼數骞筹細 2- 6v锛涗綆鐢靛钩锛?2--6v锛?/p>

鎬ц兘鍙傛暟锛毬?/p>

鐢电紗鏈€澶ц窛绂伙細4000*0.3048=1219绫筹紱浼犺緭閫熷害90kbps锛?/p>

rs485鑺墖锛氫綔涓轰竴绉嶅父鐢ㄧ殑閫氳鎺ュ彛鍣ㄤ欢锛?rs-485/rs-422 鑺墖鍙互鍦ㄨ澶氬崐瀵间綋鍏徃鐨勨€滄爣鍑嗘帴鍙e櫒浠垛€濇爮鐩腑鈥滄敹鍙戝櫒鈥濈被鍏冧欢涓壘鍒板搴旂殑鍨嬪彿锛涙瘮濡?sipex 鍏徃(鍣ㄤ欢鍓嶇紑涓?sp)銆?maxim 鍏徃(鍣ㄤ欢鍓嶇紑涓?max)銆?ti 鍏徃(鍣ㄤ欢鍓嶇紑涓?sn)銆?intersil 鍏徃(鍣ㄤ欢鍓嶇紑涓?isl 鎴?ltc)绛夊悇澶у崐瀵间綋鍏徃銆?/p>

9.3 涓€涓讳竴浠庨€氫俊

9.3.1 涓绘満鎺ョ嚎

寮曡剼杩炴帴

聽鍙戦€佹暟鎹細de寮曡剼浣胯兘涓洪珮鐢靛钩锛屽彲浠ュ彂閫侊紝鍚屾椂鎶奟e鎺ユ敹鍏抽棴锛岃緭鍑洪珮鐢靛钩锛?/p>

鎺ユ敹鏁版嵁锛歊e寮曡剼浣胯兘涓轰綆鐢靛钩锛屽彲浠ユ帴鏀讹紝鍚屾椂鎶奃e鍙戦€佸叧闂紝杈撳嚭浣庣數骞陈?/p>

聽pg8寮曡剼杈撳嚭锛氶珮鐢靛钩鍙戦€佹暟鎹紱浣庣數骞虫帴鏀舵暟鎹?/p>

聽9.3.2 涓涙満鎺ョ嚎

9.3.3 涓讳粠鏈烘帴绾垮師鐞喡?/p>

9.4 涓绘満绋嬪簭聽

#include "rs485.h" // device header

#define re_de pgout(8) //鍙戦€?鎺ユ敹鍣ㄥ叡鐢ㄤ竴涓紩鑴?/p>

void rs485_init(int bps)

{

gpio_inittypedef u2_txrx,re;

usart_inittypedef u2;

nvic_inittypedef u2_nvic;

rcc_ahb1periphclockcmd(rcc_ahb1periph_gpioa|rcc_ahb1periph_gpiog,enable);

rcc_apb1periphclockcmd(rcc_apb1periph_usart2, enable);

gpio_pinafconfig(gpioa,gpio_pinsource2,gpio_af_usart2);

gpio_pinafconfig(gpioa,gpio_pinsource3,gpio_af_usart2);

//pg8-鍙戦€?鎺ユ敹鍣ㄤ娇鑳?/p>

re.gpio_mode =gpio_mode_out;

re.gpio_otype = gpio_otype_pp;

re.gpio_pin = gpio_pin_8;

re.gpio_pupd = gpio_pupd_down; //榛樿涓嬫媺

re.gpio_speed = gpio_high_speed;

gpio_init(gpiog,&re);

//pa9-鍙戦€?/p>

u2_txrx.gpio_mode =gpio_mode_af;

u2_txrx.gpio_otype = gpio_otype_pp;

u2_txrx.gpio_pin = gpio_pin_2;

u2_txrx.gpio_pupd = gpio_pupd_up; //榛樿涓嬫媺

u2_txrx.gpio_speed = gpio_high_speed;

gpio_init(gpioa,&u2_txrx); //鏍规嵁u2_txrx閰嶇疆鐨勫弬鏁拌繘琛屽垵濮嬪寲

//pa10-鎺ユ敹

u2_txrx.gpio_mode =gpio_mode_af;

u2_txrx.gpio_otype = gpio_otype_pp;

u2_txrx.gpio_pin = gpio_pin_3;

u2_txrx.gpio_pupd = gpio_pupd_nopull; //榛樿涓嬫媺

u2_txrx.gpio_speed = gpio_high_speed;

gpio_init(gpioa,&u2_txrx);

//usart

u2.usart_baudrate=bps; //娉㈢壒鐜?/p>

u2.usart_hardwareflowcontrol=usart_hardwareflowcontrol_none; //鏃犵‖浠舵祦

u2.usart_mode=usart_mode_tx|usart_mode_rx; //鍙戦€佸拰鎺ユ敹

u2.usart_parity=usart_parity_no; //鏃犳牎楠?/p>

u2.usart_stopbits=usart_stopbits_1; //鍋滄浣?/p>

u2.usart_wordlength=usart_wordlength_8b; //鏁版嵁浣?/p>

usart_init(usart2, &u2); //鏍规嵁u2閰嶇疆鐨勫弬鏁拌繘琛屽垵濮嬪寲

//璁板緱鍒嗗紑鍐欎腑鏂?/p>

usart_itconfig(usart2, usart_it_rxne,enable); //浣胯兘涓插彛鎺ユ敹涓柇

usart_itconfig(usart2, usart_it_idle,enable); //浣胯兘涓插彛绌洪棽涓柇

u2_nvic.nvic_irqchannel = usart2_irqn;

u2_nvic.nvic_irqchannelpreemptionpriority = 1; //鎶㈠崰涓?

u2_nvic.nvic_irqchannelsubpriority = 1;//鍝嶅簲涓?

u2_nvic.nvic_irqchannelcmd = enable;

nvic_init(&u2_nvic);

usart_cmd(usart2, enable); //浣胯兘涓插彛杩涜宸ヤ綔

}

/********************************************************************

鍑芥暟鍔熻兘锛氫覆鍙?鍙戦€?涓瓧鑺傜殑瀛楃鏁版嵁

鍙傛暟1锛歞ata锛氫綘瑕佸彂閫佺殑鏁版嵁

鍙傛暟2锛氭棤

杩斿洖鍊硷細鏃?/p>

浣滆€咃細xxx

********************************************************************/

void rs485_sendbyte(char data)

{

re_de=1; //浣胯兘485鍙戦€?/p>

while(!(usart_getflagstatus(usart2,usart_flag_tc))); //绛夊緟鍒ゆ柇鍙戦€佸瘎瀛樺櫒涓虹┖

usart_senddata(usart2,data);

while(!(usart_getflagstatus(usart2,usart_flag_tc))); //绛夊緟涓虹┖锛岃鏄庡彂閫佸畬姣?/p>

re_de=0; //鍏抽棴鍙戦€侊紝榛樿鎺ユ敹

}

/********************************************************************

鍑芥暟鍔熻兘锛氫覆鍙?鍙戦€佷竴涓插瓧绗︽暟鎹?/p>

鍙傛暟1锛歞ata锛氫綘瑕佸彂閫佺殑鏁版嵁

鍙傛暟2锛氭棤

杩斿洖鍊硷細鏃?/p>

浣滆€咃細xxx

********************************************************************/

void rs485_sendstring(char *data)

{

re_de=1; //浣胯兘485鍙戦€?/p>

while(*data != '\0')//寰幆鍙戦€侊紝鐩村埌閬囧埌\0锛屽仠姝㈠彂閫?/p>

{

while(!(usart_getflagstatus(usart2,usart_flag_tc))); //绛夊緟鍒ゆ柇鍙戦€佸瘎瀛樺櫒涓虹┖

usart_senddata(usart2,*data );

}

while(!(usart_getflagstatus(usart2,usart_flag_tc))); //绛夊緟瀛楃涓叉渶鍚庝竴涓暟鎹彂閫佸畬姣?/p>

re_de=0; //鍏抽棴鍙戦€侊紝榛樿鎺ユ敹

}

//鎺ユ敹涓柇 绌洪棽涓柇

struct u2_data rs485={0,0,0}; //瀹氫箟缁撴瀯浣撳彉閲忥紝鍚屾椂鍒濆鍖栦负0

//鎺ユ敹涓柇锛氭瘡鏀跺埌涓€涓瓧绗︽暟鎹氨浼氭墽琛屼竴娆sart2_irqhandler涓柇鏈嶅姟鍑芥暟

//绌洪棽涓柇锛氭敹瀹屾暟鎹箣鍚庯紝涓插彛浜х敓绌洪棽锛屼細鑷姩鎵ц涓€娆sart2_irqhandler涓柇鏈嶅姟鍑芥暟

void usart2_irqhandler(void)

{

if(usart_getitstatus(usart2, usart_it_rxne)==set) //鎺ユ敹涓柇锛屽瓨鍌ㄦ暟鎹?/p>

{

rs485.buf[rs485.len]=usart_receivedata(usart2); //璇绘暟鎹苟娓呴櫎涓柇鏍囧織浣?/p>

rs485.len ; //鑷锛屼负涓嬩釜鏁版嵁瀛樺偍鍋氬噯澶?/p>

}else if(usart_getitstatus(usart2, usart_it_idle)==set) //绌洪棽涓柇锛屾帴鏀舵暟鎹粨鏉?/p>

{

usart_clearitpendingbit(usart2, usart_it_idle); //璇籗r

usart_receivedata(usart2); //璇籇r

rs485.ok_flag=1; //鎺ユ敹瀹屾垚

rs485.buf[rs485.len]='\0'; //娣诲姞缁撴潫绗?

}

}

9.5 浠庢満绋嬪簭

#include "rs485.h" // device header

#include "delay.h"

#define re_de paout(12)

void rs485_init(int bps)

{

gpio_inittypedef u3_txrx,re;

usart_inittypedef u3;

nvic_inittypedef nvic_u3;

rcc_apb1periphclockcmd(rcc_apb1periph_usart3, enable);

rcc_apb2periphclockcmd(rcc_apb2periph_gpioa|rcc_apb2periph_gpiob, enable); //rcc

re.gpio_mode=gpio_mode_out_pp; //澶嶇敤鎺ㄦ尳杈撳嚭妯″紡 gpio

re.gpio_pin=gpio_pin_12; //寮曡剼9

re.gpio_speed=gpio_speed_50mhz; //鏈€楂橀€?0mhz

gpio_init(gpioa, &re); //鏍规嵁u1_txrx閰嶇疆鐨勫弬鏁拌繘琛屽垵濮嬪寲

//pb10鍙戦€?/p>

u3_txrx.gpio_mode=gpio_mode_af_pp; //澶嶇敤鎺ㄦ尳杈撳嚭妯″紡 gpio

u3_txrx.gpio_pin=gpio_pin_10; //寮曡剼9

u3_txrx.gpio_speed=gpio_speed_50mhz; //鏈€楂橀€?0mhz

gpio_init(gpiob, &u3_txrx); //鏍规嵁u1_txrx閰嶇疆鐨勫弬鏁拌繘琛屽垵濮嬪寲

//pb11-鎺ユ敹

u3_txrx.gpio_mode=gpio_mode_ipu; //涓婃媺杈撳叆妯″紡

u3_txrx.gpio_pin=gpio_pin_11; //寮曡剼10

u3_txrx.gpio_speed=gpio_speed_50mhz; //鏈€楂橀€?0mhz

gpio_init(gpiob, &u3_txrx); //鏍规嵁u1_txrx閰嶇疆鐨勫弬鏁拌繘琛屽垵濮嬪寲

//usart

u3.usart_baudrate=bps; //娉㈢壒鐜?/p>

u3.usart_hardwareflowcontrol=usart_hardwareflowcontrol_none; //鏃犵‖浠舵祦

u3.usart_mode=usart_mode_tx|usart_mode_rx; //鍙戦€佸拰鎺ユ敹

u3.usart_parity=usart_parity_no; //鏃犳牎楠?/p>

u3.usart_stopbits=usart_stopbits_1; //鍋滄浣?/p>

u3.usart_wordlength=usart_wordlength_8b; //鏁版嵁浣?/p>

usart_init(usart3, &u3); //鏍规嵁u1閰嶇疆鐨勫弬鏁拌繘琛屽垵濮嬪寲

nvic_u3.nvic_irqchannel=usart3_irqn; //璁剧疆鐨凬vic浼樺厛绾х殑涓柇缂栧彿

nvic_u3.nvic_irqchannelcmd=enable;

nvic_u3.nvic_irqchannelpreemptionpriority=2; //鎶㈠崰浼樺厛绾?/p>

nvic_u3.nvic_irqchannelsubpriority=0; //鍝嶅簲浼樺厛绾?/p>

nvic_init(&nvic_u3);

//璁板緱鍒嗗紑鍐欎腑鏂?/p>

usart_itconfig(usart3, usart_it_rxne,enable); //浣胯兘涓插彛鎺ユ敹涓柇

usart_itconfig(usart3, usart_it_idle,enable); //浣胯兘涓插彛绌洪棽涓柇

//nvic_enableirq(37); //浣胯兘rs485涓柇缂栧彿

usart_cmd(usart3, enable); //浣胯兘涓插彛杩涜宸ヤ綔

re_de=0; //榛樿鎺ユ敹鏁版嵁

}

/********************************************************************

鍑芥暟鍔熻兘锛氫覆鍙?鍙戦€?涓瓧鑺傜殑瀛楃鏁版嵁

鍙傛暟1锛歞ata锛氫綘瑕佸彂閫佺殑鏁版嵁

鍙傛暟2锛氭棤

杩斿洖鍊硷細鏃?/p>

浣滆€咃細xxx

********************************************************************/

void rs485_sendbyte(char data)

{

re_de=1;//浣胯兘485鍙戦€?/p>

while(!(usart_getflagstatus(usart3,usart_flag_tc))); //绛夊緟鍒ゆ柇鍙戦€佸瘎瀛樺櫒涓虹┖

usart_senddata(usart3,data);

while(!(usart_getflagstatus(usart3,usart_flag_tc))); //绛夊緟涓虹┖,鍙戦€佸畬鎴?/p>

re_de=0; //鍏抽棴鍙戦€侊紝榛樿鎺ユ敹

}

/********************************************************************

鍑芥暟鍔熻兘锛氫覆鍙?鍙戦€佷竴涓插瓧绗︽暟鎹?/p>

鍙傛暟1锛歞ata锛氫綘瑕佸彂閫佺殑鏁版嵁

鍙傛暟2锛氭棤

杩斿洖鍊硷細鏃?/p>

浣滆€咃細xxx

********************************************************************/

void rs485_sendstring(char *data)

{

re_de=1; //浣胯兘485鍙戦€?/p>

while(*data != '\0')//寰幆鍙戦€侊紝鐩村埌閬囧埌\0锛屽仠姝㈠彂閫?/p>

{

while(!(usart_getflagstatus(usart3,usart_flag_tc))); //绛夊緟鍒ゆ柇鍙戦€佸瘎瀛樺櫒涓虹┖

usart_senddata(usart3,*data );

}

while(!(usart_getflagstatus(usart3,usart_flag_tc))); //绛夊緟瀛楃涓叉渶鍚庝竴涓暟鎹彂閫佸畬姣?/p>

re_de=0; //鍏抽棴鍙戦€侊紝榛樿鎺ユ敹

}

// 鍘熸潵鐨?/p>

//鎺ユ敹涓柇 绌洪棽涓柇

struct u3_data rs485={0,0,0}; //瀹氫箟缁撴瀯浣撳彉閲忥紝鍚屾椂鍒濆鍖栦负0

//鎺ユ敹涓柇锛氭瘡鏀跺埌涓€涓瓧绗︽暟鎹氨浼氭墽琛屼竴娆s485_irqhandler涓柇鏈嶅姟鍑芥暟

//绌洪棽涓柇锛氭敹瀹屾暟鎹箣鍚庯紝涓插彛浜х敓绌洪棽锛屼細鑷姩鎵ц涓€娆s485_irqhandler涓柇鏈嶅姟鍑芥暟

void usart3_irqhandler(void)

{

if(usart_getitstatus(usart3, usart_it_rxne)==set) //鎺ユ敹涓柇锛屽瓨鍌ㄦ暟鎹?/p>

{

rs485.buf[rs485.len]=usart_receivedata(usart3); //璇绘暟鎹苟娓呴櫎涓柇鏍囧織浣?/p>

rs485.len ; //鑷锛屼负涓嬩釜鏁版嵁瀛樺偍鍋氬噯澶?

}else if(usart_getitstatus(usart3, usart_it_idle)==set) //绌洪棽涓柇锛屾帴鏀舵暟鎹粨鏉?/p>

{

usart_clearitpendingbit(usart3, usart_it_idle); //璇籗r

usart_receivedata(usart3); //璇籇r

rs485.ok_flag=1; //鎺ユ敹瀹屾垚

rs485.buf[rs485.len]='\0'; //娣诲姞缁撴潫绗?/p>

}

}

9.6 涓€涓诲浠?鑷畾涔夊崗璁?/p>

9.6.1 鎼缓鑷畾涔夊崗璁?/p>

聽 閫氳鍗忚鍙堢о閫氫俊瑙勭▼锛屾槸鎸囬€氫俊鍙屾柟瀵规暟鎹紶閫佹帶鍒剁殑涓€绉嶇害瀹氥€傜害瀹氫腑鍖呮嫭瀵规暟鎹牸寮忥紝鍚屾鏂瑰紡锛屼紶閫侀€熷害锛屼紶閫佹楠わ紝妫€绾犻敊鏂瑰紡浠ュ強鎺у埗瀛楃瀹氫箟绛夐棶棰樺仛鍑虹粺涓€瑙勫畾锛岄€氫俊鍙屾柟蹇呴』鍏卞悓閬靛畧銆?/p>

鎼缓鑷畾涔夊崗璁殑璇濓紝閭d箞鑷繁鍐欑殑绋嬪簭锛屽氨鏍规嵁鑷繁鍒跺害鐨勮姹傛潵

9.6.2 甯歌鐨勫崗璁鍒?/p>

甯ф暟鎹紙鏁版嵁鍖咃級锛?/p>

甯歌鐨勬暟鎹寘缁撴瀯

甯уご锛氫竴甯ф暟鎹紑濮嬶紝鍙互浣跨敤澶氫釜瀛楄妭銆?鍋囧浠ヤ竴涓瓧鑺傦細0xff 聽----鑷繁瀹氫箟銆傚湴鍧€淇℃伅锛氳窡鍝釜璁惧杩涜閫氫俊锛堢被鍨嬩簬iic鍣ㄤ欢鍦板潃锛?---0x01 聽0x02 聽鑺墖id锛涙瘮濡傛垜浠幇鍦ㄦ槸涓€涓诲浠庯紝閭d箞杩欎釜鍦板潃淇℃伅鍙互鐢ㄤ簬琛ㄧず浠庢満鐨処d缂栧彿鏁版嵁绫诲瀷锛氭暟鎹被鍨嬶細濡?0x01 鈥撲唬琛ㄥ彂鐨勬槸瀛楃銆?0x02 鈥撲唬琛?6杩涘埗 聽 ---- 绫讳技鍛戒护锛涙暟鎹暱搴︼細鏁版嵁闀垮害锛?--- 聽濡傛灉鍙戦€佺殑鏁版嵁澶т簬256涓瓧鑺傦紝鑷冲皯鐢?涓瓧鑺傝〃绀?聽0x00 0x05锛涙暟鎹潡锛氭暟鎹紝鍙戦€佺殑鏁版嵁锛涙楠岀爜锛氭眰鍜岋紝鎴栬€呴€傚簲crc16/crc8绛夋牎楠岀畻娉曪紱甯у熬锛氫竴甯ф暟鎹粨鏉燂紝鍙互浣跨敤澶氫釜瀛楄妭銆?鍋囧浠ヤ竴涓瓧鑺傦細0xfe 聽----鑷繁瀹氫箟銆偮?/p>

瀹氫箟浠庢満鍗忚缁撴瀯浣擄細聽

聽9.6.3聽rs485鑷畾涔夊崗璁?1涓诲浠庨€氫俊-鎸夐敭鎺у埗-鍗曟鏁版嵁閫氫俊绋嬪簭

涓绘満锛?/p>

#include "rs485.h" // device header

#define re_de pgout(8) //鍙戦€?鎺ユ敹鍣ㄥ叡鐢ㄤ竴涓紩鑴?/p>

void rs485_init(int bps)

{

gpio_inittypedef u2_txrx,re;

usart_inittypedef u2;

nvic_inittypedef u2_nvic;

rcc_ahb1periphclockcmd(rcc_ahb1periph_gpioa|rcc_ahb1periph_gpiog,enable);

rcc_apb1periphclockcmd(rcc_apb1periph_usart2, enable);

gpio_pinafconfig(gpioa,gpio_pinsource2,gpio_af_usart2);

gpio_pinafconfig(gpioa,gpio_pinsource3,gpio_af_usart2);

//pg8-鍙戦€?鎺ユ敹鍣ㄤ娇鑳?/p>

re.gpio_mode =gpio_mode_out;

re.gpio_otype = gpio_otype_pp;

re.gpio_pin = gpio_pin_8;

re.gpio_pupd = gpio_pupd_down; //榛樿涓嬫媺

re.gpio_speed = gpio_high_speed;

gpio_init(gpiog,&re);

//pa9-鍙戦€?/p>

u2_txrx.gpio_mode =gpio_mode_af;

u2_txrx.gpio_otype = gpio_otype_pp;

u2_txrx.gpio_pin = gpio_pin_2;

u2_txrx.gpio_pupd = gpio_pupd_up; //榛樿涓嬫媺

u2_txrx.gpio_speed = gpio_high_speed;

gpio_init(gpioa,&u2_txrx); //鏍规嵁u2_txrx閰嶇疆鐨勫弬鏁拌繘琛屽垵濮嬪寲

//pa10-鎺ユ敹

u2_txrx.gpio_mode =gpio_mode_af;

u2_txrx.gpio_otype = gpio_otype_pp;

u2_txrx.gpio_pin = gpio_pin_3;

u2_txrx.gpio_pupd = gpio_pupd_nopull; //榛樿涓嬫媺

u2_txrx.gpio_speed = gpio_high_speed;

gpio_init(gpioa,&u2_txrx);

//usart

u2.usart_baudrate=bps; //娉㈢壒鐜?/p>

u2.usart_hardwareflowcontrol=usart_hardwareflowcontrol_none; //鏃犵‖浠舵祦

u2.usart_mode=usart_mode_tx|usart_mode_rx; //鍙戦€佸拰鎺ユ敹

u2.usart_parity=usart_parity_no; //鏃犳牎楠?/p>

u2.usart_stopbits=usart_stopbits_1; //鍋滄浣?/p>

u2.usart_wordlength=usart_wordlength_8b; //鏁版嵁浣?/p>

usart_init(usart2, &u2); //鏍规嵁u2閰嶇疆鐨勫弬鏁拌繘琛屽垵濮嬪寲

//璁板緱鍒嗗紑鍐欎腑鏂?/p>

usart_itconfig(usart2, usart_it_rxne,enable); //浣胯兘涓插彛鎺ユ敹涓柇

usart_itconfig(usart2, usart_it_idle,enable); //浣胯兘涓插彛绌洪棽涓柇

u2_nvic.nvic_irqchannel = usart2_irqn;

u2_nvic.nvic_irqchannelpreemptionpriority = 1; //鎶㈠崰涓?

u2_nvic.nvic_irqchannelsubpriority = 1;//鍝嶅簲涓?

u2_nvic.nvic_irqchannelcmd = enable;

nvic_init(&u2_nvic);

usart_cmd(usart2, enable); //浣胯兘涓插彛杩涜宸ヤ綔

}

/********************************************************************

鍑芥暟鍔熻兘锛氫覆鍙?鍙戦€?涓瓧鑺傜殑瀛楃鏁版嵁

鍙傛暟1锛歞ata锛氫綘瑕佸彂閫佺殑鏁版嵁

鍙傛暟2锛氭棤

杩斿洖鍊硷細鏃?/p>

浣滆€咃細xxx

********************************************************************/

void rs485_sendbyte(char data)

{

re_de=1; //浣胯兘485鍙戦€?/p>

while(!(usart_getflagstatus(usart2,usart_flag_tc))); //绛夊緟鍒ゆ柇鍙戦€佸瘎瀛樺櫒涓虹┖

usart_senddata(usart2,data);

while(!(usart_getflagstatus(usart2,usart_flag_tc))); //绛夊緟涓虹┖锛岃鏄庡彂閫佸畬姣?/p>

re_de=0; //鍏抽棴鍙戦€侊紝榛樿鎺ユ敹

}

/********************************************************************

鍑芥暟鍔熻兘锛氫覆鍙?鍙戦€佷竴涓插瓧绗︽暟鎹?/p>

鍙傛暟1锛歞ata锛氫綘瑕佸彂閫佺殑鏁版嵁

鍙傛暟2锛氭棤

杩斿洖鍊硷細鏃?/p>

浣滆€咃細xxx

********************************************************************/

void rs485_sendstring(char *data)

{

re_de=1; //浣胯兘485鍙戦€?/p>

while(*data != '\0')//寰幆鍙戦€侊紝鐩村埌閬囧埌\0锛屽仠姝㈠彂閫?/p>

{

while(!(usart_getflagstatus(usart2,usart_flag_tc))); //绛夊緟鍒ゆ柇鍙戦€佸瘎瀛樺櫒涓虹┖

usart_senddata(usart2,*data );

}

while(!(usart_getflagstatus(usart2,usart_flag_tc))); //绛夊緟瀛楃涓叉渶鍚庝竴涓暟鎹彂閫佸畬姣?/p>

re_de=0; //鍏抽棴鍙戦€侊紝榛樿鎺ユ敹

}

void rs485_sendlenstring(char *data,u16 len)

{

re_de=1; //浣胯兘485鍙戦€?/p>

while(len)//寰幆鍙戦€侊紝鐩村埌閬囧埌\0锛屽仠姝㈠彂閫?/p>

{

while(!(usart_getflagstatus(usart2,usart_flag_tc))); //绛夊緟鍒ゆ柇鍙戦€佸瘎瀛樺櫒涓虹┖

usart_senddata(usart2,*data );

len--;

}

while(!(usart_getflagstatus(usart2,usart_flag_tc))); //绛夊緟瀛楃涓叉渶鍚庝竴涓暟鎹彂閫佸畬姣?/p>

re_de=0; //鍏抽棴鍙戦€侊紝榛樿鎺ユ敹

}

//鎺ユ敹涓柇 绌洪棽涓柇

struct u2_data rs485={0,0,0}; //瀹氫箟缁撴瀯浣撳彉閲忥紝鍚屾椂鍒濆鍖栦负0

//鎺ユ敹涓柇锛氭瘡鏀跺埌涓€涓瓧绗︽暟鎹氨浼氭墽琛屼竴娆sart2_irqhandler涓柇鏈嶅姟鍑芥暟

//绌洪棽涓柇锛氭敹瀹屾暟鎹箣鍚庯紝涓插彛浜х敓绌洪棽锛屼細鑷姩鎵ц涓€娆sart2_irqhandler涓柇鏈嶅姟鍑芥暟

void usart2_irqhandler(void)

{

if(usart_getitstatus(usart2, usart_it_rxne)==set) //鎺ユ敹涓柇锛屽瓨鍌ㄦ暟鎹?/p>

{

rs485.buf[rs485.len]=usart_receivedata(usart2); //璇绘暟鎹苟娓呴櫎涓柇鏍囧織浣?/p>

rs485.len ; //鑷锛屼负涓嬩釜鏁版嵁瀛樺偍鍋氬噯澶?/p>

}else if(usart_getitstatus(usart2, usart_it_idle)==set) //绌洪棽涓柇锛屾帴鏀舵暟鎹粨鏉?/p>

{

usart_clearitpendingbit(usart2, usart_it_idle); //璇籗r

usart_receivedata(usart2); //璇籇r

rs485.ok_flag=1; //鎺ユ敹瀹屾垚

rs485.buf[rs485.len]='\0'; //娣诲姞缁撴潫绗?

}

}

//slave s1={0xfd,1,0,0,{0},0,0xfe}; //瀹氫箟缁撴瀯浣擄紝骞跺垵濮嬪寲

master m1={0xfd,0,0,0xfe};

//鍙戦€佹暟鎹寘

void master_senddatapackage(u8 id,u8 cmd)

{

m1.id=id; //鍛煎彨浠庢満1

m1.cmd=cmd; //涓婁紶娓╁害銆佸厜鐓с€佹湁姣掓皵浣?/p>

//void rs485_sendlenstring(char *data,u16 len)

rs485_sendbyte(m1.head); //甯уご

rs485_sendbyte(m1.id); //浠庢満id=0x2c

rs485_sendbyte(m1.cmd); //鍛戒护

rs485_sendbyte(m1.end); //甯у熬

}

main.c

#include "main.h"

//extern const unsigned char gimage_image[307200];

xpt2046 xy;

rtc_timetypedef time; //鏃堕棿

rtc_datetypedef date; //鏃ユ湡

int main(void)

{

int i;

u8 m1_check=0;

float wendu=0,shidu=0;

u8 key_number=0;

u8 buf[2];

char rtc_buf[64];

nvic_prioritygroupconfig(nvic_prioritygroup_2); //nvic 缁?锛屾姠2鍗?

systick_init(); //绯荤粺婊寸瓟寤舵椂

led_init(); //led

beep_init(); //铚傞福鍣?/p>

key_init();

//key_exti_init(); //鎸夐敭澶栭儴涓柇

usart1_init(115200); //涓插彛鍒濆鍖?15200

//led1_pwm_init(8400,100) ; //168鍒嗛8400=21000hz=2.1khz 100涓烘瘮杈冩渶澶у€?/p>

//led2_pwm_init(8400,100); //168鍒嗛8400=21000hz=2.1khz 100涓烘瘮杈冩渶澶у€?/p>

w25q64_spi1_init(); //w25q64鍒濆鍖?/p>

w25q64_readid(buf); //璇籌d

printf("w25q64 id:0x%x 0x%x\r\n",buf[0],buf[1]);

lcd_ili9486_init(); //lcd鍒濆鍖?/p>

touch_init(); //瑙︽懜灞忓垵濮嬪寲

delay_ms(1000);

touch_adjust(); //瑙︽懜灞忔牎鍑?/p>

printf("鏍″噯鎴愬姛\r\n");

rtc_time_init(22,8,12,11,18,50,5);

//wwdg_init(127,125); //绐楀彛鍊?27锛岃鏁板櫒鍊间负125锛屽嵆鍒濆鍖栧€硷紝涔熸槸鍠傜嫍鍊硷紝涓嶈兘澶т簬绐楀彛鍊?27锛屽惁鍒欎篃浼氳е鍙戝浣?/p>

rs485_init(115200);

//tim4_init(8400,9000); //瀹氭椂0.9s锛岃繘琛屽杺鐙?/p>

//iwdg_init(iwdg_prescaler_32,1000); //1s涔嬪唴瑕佸杺鐙楋紝棰勫垎棰戜负32,32khz/32=1khz锛?s=1khz锛?/p>

//閲嶈杞藉€?涓暟涓?ms锛屽啓鍏?000琛ㄧず1000ms鍐呰鍠傜嫍锛屽惁鍒欎細浜х敓澶嶄綅

// for(i=0;i<15;i )

// {

// delay_ms(1000);

// if(font_flag==1) break;

// }

//

// if(font_flag==1 && i < 10) //寮€鏈?0s鍐呮寜涓嬫寜閿紝瑙﹀彂涓嬭浇瀛楀簱鎿嶄綔锛屾墽琛屼笅杞藉姛鑳?/p>

// {

// w25q64_write_gb2312_ascii(); //涓嬭浇瀛楀簱

// }

//lcd_drawrectangle(10, 150,60,200,red); //鏄剧ず涓€涓煩褰?/p>

while (1)

{

key_number=key_scan();

if(key_number==1)

{

master_senddatapackage(1,0xff);

printf("鍛煎彨浠庢満1\r\n");

}else if(key_number==2)

{

master_senddatapackage(2,0xff);

printf("鍛煎彨浠庢満2\r\n");

}

//涓绘満浣跨敤瑙︽懜灞忔帶鍒讹紝閫夋嫨閲囬泦瀵瑰簲鐨勪粠鏈烘暟鎹苟鏄剧ず

if(rs485.ok_flag==1) //鏀跺埌浠庢満杩斿洖鏁版嵁

{

printf("涓绘満鏀跺埌浠庢満%d杩斿洖鐨勬暟鎹甛r\n",rs485.buf[1]);

if(rs485.buf[0] == m1.head && rs485.buf[rs485.len-1] == m1.end) //甯уご鍜屽抚灏炬纭?/p>

{

m1_check=0; //鏍¢獙鐮佹竻0

for(i=3;i<15;i )

{

m1_check =rs485.buf[i];

//printf("涓绘満涓嬫爣%d鍊?%d\r\n",i,rs485.buf[i]); //鏀跺埌鐨勬暟鎹?/p>

//printf("璁$畻鍜屽€?%d\r\n",m1_check); //鏀跺埌鐨勬暟鎹?/p>

}

//printf("涓绘満璁$畻鍑烘潵鐨勬牎楠岀爜:%d\r\n",m1_check);

//printf("浠庢満鏍¢獙鐮?%d\r\n",rs485.buf[rs485.len-2]);

if(m1_check==rs485.buf[rs485.len-2])

{

printf("鏍¢獙ok\r\n");

shidu=rs485.buf[3] (rs485.buf[4]/100.0); //56.000000

wendu=rs485.buf[5] (rs485.buf[6]/100.0); //28.560000

printf("浠庢満%d 娓╁害:%.2f 婀垮害:%.2f\r\n",rs485.buf[1],wendu,shidu);

}

}

rs485.ok_flag=0;

rs485.len=0;

memset(rs485.buf,0,256); //娓?

}

/*

delay_ms(900);

rtc_gettime(rtc_format_bin, &time);

rtc_getdate(rtc_format_bin, &date);

printf("%d骞?d鏈?d鏃?%d鏃?%d鍒?%d绉抃r\n",date.rtc_year,date.rtc_month,date.rtc_date,time.rtc_hours,time.rtc_minutes,time.rtc_seconds);

sprintf(rtc_buf,"20%d骞?d鏈?d鏃?d鏃?02d鍒?02d绉?,date.rtc_year,date.rtc_month,date.rtc_date,time.rtc_hours,time.rtc_minutes,time.rtc_seconds);

lcd_show_gb2312_ascii(100,20,white,red,rtc_buf);

if(t_pen==0)

{

get_xpt2046_adjust_xyval(&xy); //鑾峰彇鏍″噯鍚庣殑鍧愭爣鍊?/p>

if((xy.xval >=10 && xy.xval<=60) && (xy.yval >=150 && xy.yval<=200))

{

printf("鎸変笅鐣岄潰鎸夐挳\r\n");

rtc_set_time(15,30,52); //淇敼鏃堕棿

}

printf("x杞?%d y杞?%d\r\n",xy.xval,xy.yval);

while(!t_pen)delay_ms(10);

}

*/

/*

for(i=0;i<100;i )

{

delay_ms(10);

tim_setcompare1(tim10,i); //淇敼鍗犵┖姣?浣庣數骞冲崰绌烘瘮涓嶆柇澧炲姞锛岃秺鏉ヨ秺浜?/p>

tim_setcompare1(tim14,i); //淇敼鍗犵┖姣?浣庣數骞冲崰绌烘瘮涓嶆柇澧炲姞锛岃秺鏉ヨ秺浜?/p>

}

for(i=100;i>=0;i--)

{

delay_ms(10);

tim_setcompare1(tim10,i); //淇敼鍗犵┖姣?浣庣數骞冲崰绌烘瘮涓嶆柇鍑忓皯锛岃秺鏉ヨ秺鏆?/p>

tim_setcompare1(tim14,i); //淇敼鍗犵┖姣?浣庣數骞冲崰绌烘瘮涓嶆柇澧炲姞锛岃秺鏉ヨ秺浜?/p>

}

*/

/*

if(t_pen==0){

get_xpt2046_adjust_xyval(&xy); //鑾峰彇鏍″噯鍚庣殑鍧愭爣鍊?/p>

if((xy.xval >=10 && xy.xval<=60) && (xy.yval >=150 && xy.yval<=200))

{

printf("鎸変笅鐣岄潰鎸夐挳\r\n");

}

printf("x杞?%d y杞?%d\r\n",xy.xval,xy.yval);

while(!t_pen)delay_ms(10);

}

*/

//瑙︽懜灞?lcd浣滀笟锛?/p>

// if(u1.ok_flag==1) //璇存槑涓插彛鎺ユ敹瀹屾暟鎹?/p>

// {

// printf("%s\r\n",u1.buf); //鍙戦€佷竴涓叉暟鎹埌鐢佃剳鍥炴樉

// //娓?

// u1.ok_flag=0;

// u1.len=0;

// memset(u1.buf,0,sizeof(u1.buf));

// }

/*

for(i=0;i<100;i )

{

delay_ms(10);

tim_setcompare1(tim10,i); //淇敼鍗犵┖姣?浣庣數骞冲崰绌烘瘮涓嶆柇澧炲姞锛岃秺鏉ヨ秺浜?/p>

tim_setcompare1(tim14,i); //淇敼鍗犵┖姣?浣庣數骞冲崰绌烘瘮涓嶆柇澧炲姞锛岃秺鏉ヨ秺浜?/p>

}

for(i=100;i>=0;i--)

{

delay_ms(10);

tim_setcompare1(tim10,i); //淇敼鍗犵┖姣?浣庣數骞冲崰绌烘瘮涓嶆柇鍑忓皯锛岃秺鏉ヨ秺鏆?/p>

tim_setcompare1(tim14,i); //淇敼鍗犵┖姣?浣庣數骞冲崰绌烘瘮涓嶆柇澧炲姞锛岃秺鏉ヨ秺浜?/p>

}

*/

}

}

浠庢満

485.c

#include "rs485.h" // device header

#include "delay.h"

#define re_de paout(12)

void rs485_init(int bps)

{

gpio_inittypedef u3_txrx,re;

usart_inittypedef u3;

nvic_inittypedef nvic_u3;

rcc_apb1periphclockcmd(rcc_apb1periph_usart3, enable);

rcc_apb2periphclockcmd(rcc_apb2periph_gpioa|rcc_apb2periph_gpiob, enable); //rcc

re.gpio_mode=gpio_mode_out_pp; //澶嶇敤鎺ㄦ尳杈撳嚭妯″紡 gpio

re.gpio_pin=gpio_pin_12; //寮曡剼9

re.gpio_speed=gpio_speed_50mhz; //鏈€楂橀€?0mhz

gpio_init(gpioa, &re); //鏍规嵁u1_txrx閰嶇疆鐨勫弬鏁拌繘琛屽垵濮嬪寲

//pb10鍙戦€?/p>

u3_txrx.gpio_mode=gpio_mode_af_pp; //澶嶇敤鎺ㄦ尳杈撳嚭妯″紡 gpio

u3_txrx.gpio_pin=gpio_pin_10; //寮曡剼9

u3_txrx.gpio_speed=gpio_speed_50mhz; //鏈€楂橀€?0mhz

gpio_init(gpiob, &u3_txrx); //鏍规嵁u1_txrx閰嶇疆鐨勫弬鏁拌繘琛屽垵濮嬪寲

//pb11-鎺ユ敹

u3_txrx.gpio_mode=gpio_mode_ipu; //涓婃媺杈撳叆妯″紡

u3_txrx.gpio_pin=gpio_pin_11; //寮曡剼10

u3_txrx.gpio_speed=gpio_speed_50mhz; //鏈€楂橀€?0mhz

gpio_init(gpiob, &u3_txrx); //鏍规嵁u1_txrx閰嶇疆鐨勫弬鏁拌繘琛屽垵濮嬪寲

//usart

u3.usart_baudrate=bps; //娉㈢壒鐜?/p>

u3.usart_hardwareflowcontrol=usart_hardwareflowcontrol_none; //鏃犵‖浠舵祦

u3.usart_mode=usart_mode_tx|usart_mode_rx; //鍙戦€佸拰鎺ユ敹

u3.usart_parity=usart_parity_no; //鏃犳牎楠?/p>

u3.usart_stopbits=usart_stopbits_1; //鍋滄浣?/p>

u3.usart_wordlength=usart_wordlength_8b; //鏁版嵁浣?/p>

usart_init(usart3, &u3); //鏍规嵁u1閰嶇疆鐨勫弬鏁拌繘琛屽垵濮嬪寲

nvic_u3.nvic_irqchannel=usart3_irqn; //璁剧疆鐨凬vic浼樺厛绾х殑涓柇缂栧彿

nvic_u3.nvic_irqchannelcmd=enable;

nvic_u3.nvic_irqchannelpreemptionpriority=2; //鎶㈠崰浼樺厛绾?/p>

nvic_u3.nvic_irqchannelsubpriority=0; //鍝嶅簲浼樺厛绾?/p>

nvic_init(&nvic_u3);

//璁板緱鍒嗗紑鍐欎腑鏂?/p>

usart_itconfig(usart3, usart_it_rxne,enable); //浣胯兘涓插彛鎺ユ敹涓柇

usart_itconfig(usart3, usart_it_idle,enable); //浣胯兘涓插彛绌洪棽涓柇

//nvic_enableirq(37); //浣胯兘rs485涓柇缂栧彿

usart_cmd(usart3, enable); //浣胯兘涓插彛杩涜宸ヤ綔

re_de=0; //榛樿鎺ユ敹鏁版嵁

}

/********************************************************************

鍑芥暟鍔熻兘锛氫覆鍙?鍙戦€?涓瓧鑺傜殑瀛楃鏁版嵁

鍙傛暟1锛歞ata锛氫綘瑕佸彂閫佺殑鏁版嵁

鍙傛暟2锛氭棤

杩斿洖鍊硷細鏃?/p>

浣滆€咃細xxx

********************************************************************/

void rs485_sendbyte(u8 data)

{

re_de=1;//浣胯兘485鍙戦€?/p>

while(!(usart_getflagstatus(usart3,usart_flag_tc))); //绛夊緟鍒ゆ柇鍙戦€佸瘎瀛樺櫒涓虹┖

usart_senddata(usart3,data);

while(!(usart_getflagstatus(usart3,usart_flag_tc))); //绛夊緟涓虹┖,鍙戦€佸畬鎴?/p>

re_de=0; //鍏抽棴鍙戦€侊紝榛樿鎺ユ敹

}

/********************************************************************

鍑芥暟鍔熻兘锛氫覆鍙?鍙戦€佷竴涓插瓧绗︽暟鎹?/p>

鍙傛暟1锛歞ata锛氫綘瑕佸彂閫佺殑鏁版嵁

鍙傛暟2锛氭棤

杩斿洖鍊硷細鏃?/p>

浣滆€咃細xxx

********************************************************************/

void rs485_sendstring(u8 *data)

{

re_de=1; //浣胯兘485鍙戦€?/p>

while(*data != '\0')//寰幆鍙戦€侊紝鐩村埌閬囧埌\0锛屽仠姝㈠彂閫?/p>

{

while(!(usart_getflagstatus(usart3,usart_flag_tc))); //绛夊緟鍒ゆ柇鍙戦€佸瘎瀛樺櫒涓虹┖

usart_senddata(usart3,*data );

}

while(!(usart_getflagstatus(usart3,usart_flag_tc))); //绛夊緟瀛楃涓叉渶鍚庝竴涓暟鎹彂閫佸畬姣?/p>

re_de=0; //鍏抽棴鍙戦€侊紝榛樿鎺ユ敹

}

/********************************************************************

鍑芥暟鍔熻兘锛氫覆鍙?鍙戦€佷竴涓插瓧绗︽暟鎹?/p>

鍙傛暟1锛歞ata锛氫綘瑕佸彂閫佺殑鏁版嵁

鍙傛暟2锛氭棤

杩斿洖鍊硷細鏃?/p>

浣滆€咃細xxx

********************************************************************/

void rs485_sendlenstring(u8 *data,u16 len)

{

while(len) //寰幆鍙戦€佹寚瀹氶暱搴︾殑鏁版嵁

{

//printf("%d\r\n",*data);

rs485_sendbyte( *data );

len--;

}

}

/*

typedef struct

{

u8 head; //甯уご----0xfd

u16 id; //琛ㄧず浠庢満鐨勭紪鍙?/p>

u8 cmd; //鎺у埗瀛楋紝姣斿0xff灏辨槸浠庢満涓婁紶娓╁害锛屽厜鐓с€佹湁姣掑叾瀹冪瓑绛夋暟鎹? 0:涓嶉噰闆嗘暟鎹紝1锛氭俯搴? 2锛氬厜鐓?3锛氭湁姣掓皵浣?0xff锛氭墍鏈夌殑

u8 len; //鏁版嵁闀垮害

u8 buf[256]; //鍙戦€佺殑鏁版嵁

u8 check; //鏍¢獙鐮?/p>

u8 end; //甯у熬

}slave; //浠庢満鍗忚

*/

slave s1={0xfd,1,0,{0},0,0xfe}; //瀹氫箟缁撴瀯浣擄紝骞跺垵濮嬪寲

// 鍘熸潵鐨?/p>

//鎺ユ敹涓柇 绌洪棽涓柇

struct u3_data rs485={0,0,0}; //瀹氫箟缁撴瀯浣撳彉閲忥紝鍚屾椂鍒濆鍖栦负0

//鎺ユ敹涓柇锛氭瘡鏀跺埌涓€涓瓧绗︽暟鎹氨浼氭墽琛屼竴娆s485_irqhandler涓柇鏈嶅姟鍑芥暟

//绌洪棽涓柇锛氭敹瀹屾暟鎹箣鍚庯紝涓插彛浜х敓绌洪棽锛屼細鑷姩鎵ц涓€娆s485_irqhandler涓柇鏈嶅姟鍑芥暟

void usart3_irqhandler(void)

{

if(usart_getitstatus(usart3, usart_it_rxne)==set) //鎺ユ敹涓柇锛屽瓨鍌ㄦ暟鎹?/p>

{

rs485.buf[rs485.len]=usart_receivedata(usart3); //璇绘暟鎹苟娓呴櫎涓柇鏍囧織浣?/p>

rs485.len ; //鑷锛屼负涓嬩釜鏁版嵁瀛樺偍鍋氬噯澶?

}else if(usart_getitstatus(usart3, usart_it_idle)==set) //绌洪棽涓柇锛屾帴鏀舵暟鎹粨鏉?/p>

{

usart_clearitpendingbit(usart3, usart_it_idle); //璇籗r

usart_receivedata(usart3); //璇籇r

rs485.ok_flag=1; //鎺ユ敹瀹屾垚

rs485.buf[rs485.len]='\0'; //娣诲姞缁撴潫绗?/p>

}

}

//鍙戦€佹暟鎹寘

void rs485_senddatapackage(void)

{

rs485_sendbyte(s1.head); //鍙戦€佸抚澶?/p>

rs485_sendbyte(s1.id); //浠庢満id

rs485_sendbyte(s1.len); //鏁版嵁闀垮害

rs485_sendlenstring(s1.buf,s1.len); //鍙戦€佹寚瀹氶暱搴︽暟鎹?/p>

rs485_sendbyte(s1.check); //鏍¢獙鐮?/p>

rs485_sendbyte(s1.end); //甯у熬

}

浠庢満鐨刴ain.c

#include "stm32f10x.h"

#include "delay.h"

#include "beep.h"

#include "led.h"

#include "key.h"

#include "usart1.h"

#include "cm3_bit.h"

#include "dht11.h"

#include "my_oled.h"

#include "image.h"

#include "w25q16.h"

#include "gz.h"

#include "adc1.h"

#include "dma1.h"

#include "string.h"

#include "rs485.h"

#include "tim4.h"

#include "pwm.h"

#define beep pcout(3)

int main(void) //涓诲嚱鏁?

{

int i;

char buf=0;

float cpu_temp,mq135_val,mq2_val,gz_val; //杞崲鍚庣殑cpu娓╁害

u8 size_len=0;

u16 cpu_val=0; //寰楀埌cpu鐨刟d鍊?/p>

u16 dma_buf[4]; //淇濆瓨dma鎼繍鏁版嵁

u8 temp=0;

u8 data_buf[4]={0};

float wendu=0,shidu=0;

u8 wsd_buf[32];

nvic_prioritygroupconfig(nvic_prioritygroup_2); //缁?锛?浣嶆姠鍗狅紝2浣嶅搷搴?/p>

systick_init(); //绯荤粺婊寸瓟寤舵椂

beep_init(); //beep鍒濆鍖?/p>

//led_init(); //led鐏?/p>

//key_init(); //鏅€氭寜閿?/p>

usart1_init(115200); //涓插彛1

dht11_init(); //娓╂箍搴﹀垵濮嬪寲

dht11_gettemphumidity(data_buf);

oled_init(); //oled鍒濆鍖?/p>

w25q16_init();

// exti_key_init(); //澶栭儴涓柇-pa0

// for(i=0;i<15;i )

// {

// delay_ms(1000);

// if(font_flag==1) break;

// }

//

// if(font_flag==1 && i < 10) //寮€鏈?0s鍐呮寜涓嬫寜閿紝瑙﹀彂涓嬭浇瀛楀簱鎿嶄綔锛屾墽琛屼笅杞藉姛鑳?/p>

// {

//

// w25q16_write_gb2312(); //涓嬭浇瀛楀簱

//

// }

//cpu_mq2_135_gz_adc1init(); //pa2-mq2:adc1鈥擾in2 pa1-mq135:adc1鈥擾in1

//cpu_dma1_adc1init(&cpu_val); //鍒濆鍖栧惎鍔ˋdc1鐨凪da1浼犺緭

dma1_adc1init(dma_buf); //鍒濆鍖栧惎鍔ˋdc1鐨凪da1浼犺緭

//tim4_init(7200,10000); //瀹氭椂1s

//led1_pwm_init(7200,100); //100鐨勬剰鎬濇槸锛岃鏁?00锛屽氨浼氬拰pwm鐨勬瘮杈冨瘎瀛樺櫒杩涜姣旇緝100娆★紝

rs485_init(115200);

while (1)

{

if(rs485.ok_flag==1) //涓插彛鏀跺埌鏁版嵁

{

rs485.ok_flag=0;

if(rs485.buf[1]==s1.id) //璇存槑涓绘満鍛煎彨瀵瑰簲鐨勪粠鏈虹紪鍙?

{

printf("浠庢満%d鏀跺埌涓绘満鐨勫懠鍙玕r\n",s1.id);

if(rs485.buf[0]==s1.head && rs485.buf[3]==s1.end) //瀵规瘮甯уご甯у熬

{

if(rs485.buf[2]==0) //涓嶉噰闆嗘暟鎹?/p>

{

}else if(rs485.buf[2]==1) //娓╂箍搴?/p>

{

}else if(rs485.buf[2]==2) //鍏夌収

{

}else if(rs485.buf[2]==3) //鏈夋瘨姘斾綋

{

}else if(rs485.buf[2]==0xff) //娓╂箍搴?鍏夌収 鏈夋瘨姘斾綋

{

//閲囬泦娓╂箍搴?

delay_ms(1500);

temp=dht11_gettemphumidity(data_buf);

if(temp==0)

{

//printf("閲囬泦鏍¢獙ok\r\n");

shidu=data_buf[0] (data_buf[1]/100.0); //56.000000

wendu=data_buf[2] (data_buf[3]/100.0); //28.560000

printf("浠庢満%d锛氭俯搴?%.2f 婀垮害:%.2f\r\n",s1.id,wendu,shidu);

}

shidu=data_buf[0] (data_buf[1]/100.0); //

wendu=data_buf[2] (data_buf[3]/100.0); //31.00-------"31.00"

//printf("娓╁害:%.2f 婀垮害:%.2f\r\n",wendu,shidu);

sprintf(wsd_buf,"娓╁害:%.2f 婀垮害:%.2f",wendu,shidu); //杞崲 wd_buf[]="娓╁害:31.00";

oled_show_chinesechar(0,0,wsd_buf); //oled鏄剧ず杞崲鏁版嵁

//濉厖娓╂箍搴︽暟鎹埌鏁版嵁鍖呭唴

s1.buf[0]=data_buf[0];

s1.buf[1]=data_buf[1];

s1.buf[2]=data_buf[2];

s1.buf[3]=data_buf[3];

//濉厖dma鎼繍鐨刢pu娓╁害銆乵q135銆乵q2銆佸厜鐓?/p>

s1.buf[4]=dma_buf[0]>>8; //濉厖楂樹綅

s1.buf[5]=dma_buf[0];

s1.buf[6]=dma_buf[1]>>8;

s1.buf[7]=dma_buf[1];

s1.buf[8]=dma_buf[2]>>8;

s1.buf[9]=dma_buf[2];

s1.buf[10]=dma_buf[3]>>8;

s1.buf[11]=dma_buf[3];

s1.buf[12]='\0';

s1.len=12; //鏁版嵁鏈夋晥闀垮害

//鏍¢獙鐮侊細鏁版嵁鐨勭疮绉拰锛屽緱鍑烘牎楠岀爜

s1.check=0;

for(i=0;i<12;i )

{

s1.check =s1.buf[i];

}

//printf("浠庢満鏍¢獙鐮侊細%d\r\n",s1.check);

rs485_senddatapackage(); //鍙戦€佸~鍏呭ソ鐨勬暟鎹寘

printf("浠庢満%d杩斿洖鏁版嵁瀹屾垚\r\n",s1.id);

}

}

}

rs485.ok_flag=0;

rs485.len=0;

memset(rs485.buf,0,256); //娓?

}

/*

for(i=0;i<100;i )

{

delay_ms(10);

tim_setcompare4(tim3,i); //淇敼鍗犵┖姣?浣庣數骞冲崰绌烘瘮涓嶆柇澧炲姞锛岃秺鏉ヨ秺浜?/p>

}

for(i=100;i>=0;i--)

{

delay_ms(10);

tim_setcompare4(tim3,i); //淇敼鍗犵┖姣?浣庣數骞冲崰绌烘瘮涓嶆柇鍑忓皯锛岃秺鏉ヨ秺鏆?/p>

}

*/

//浣滀笟1锛氬畬鎴怭wm鎺у埗led1

//浣滀笟2锛氬畬鎴怱tm32f4鐨勮姱鐗嘝ack鍖呭畨瑁咃紝鍚﹀垯鏃犳硶寤虹珛宸ョ▼閫夋嫨鑺墖

//浣滀笟3: 涓嬭浇stm32f4鐨勬柊寤哄伐绋嬫枃浠讹紝鐢ㄤ簬鏂板缓宸ョ▼浣跨敤锛岀劧鍚庡鎵鹃噷闈㈢殑鏂囦欢寤虹珛f4鐨勫伐绋?/p>

/*

if(u1.ok_flag==1) //涓插彛鏀跺埌鏁版嵁 鏃?20

{

if(u1.buf[0] == *"鏃? && u1.buf[1] == *("鏃? 1)) //璇存槑鏀跺埌淇敼灏忔椂

{

size_len=u1.len-3; //绠楀嚭鏄竴浣嶆暟瀛楄繕鏄?浣嶆暟瀛?/p>

if(size_len==1) //璇存槑涓轰竴浣嶆暟瀛?-9

{

hour=u1.buf[u1.len-1]-48; //杞崲涓烘暣鏁?

}else{ //涓や綅鏁?/p>

temp=(u1.buf[u1.len-2]-48)*10 (u1.buf[u1.len-1]-48) ; //杞崲涓烘暣鏁帮紝鍐嶅悎骞?

if(temp<24)hour=temp;

}

}else if(u1.buf[0] == *"鍒? && u1.buf[1] == *("鍒? 1)) //璇存槑鏀跺埌淇敼鍒嗛挓

{

size_len=u1.len-3; //绠楀嚭鏄竴浣嶆暟瀛楄繕鏄?浣嶆暟瀛?/p>

if(size_len==1) //璇存槑涓轰竴浣嶆暟瀛?-9

{

min=u1.buf[u1.len-1]-48; //杞崲涓烘暣鏁?

}else{ //涓や綅鏁?/p>

temp=(u1.buf[u1.len-2]-48)*10 (u1.buf[u1.len-1]-48) ; //杞崲涓烘暣鏁帮紝鍐嶅悎骞?

if(temp<60)min=temp;

}

}else if(u1.buf[0] == *"绉? && u1.buf[1] == *("绉? 1)) //璇存槑鏀跺埌淇敼绉?/p>

{

size_len=u1.len-3; //绠楀嚭鏄竴浣嶆暟瀛楄繕鏄?浣嶆暟瀛?

if(size_len==1) //璇存槑涓轰竴浣嶆暟瀛?-9

{

sec=u1.buf[u1.len-1]-48; //杞崲涓烘暣鏁?

}else{ //涓や綅鏁?/p>

temp=(u1.buf[u1.len-2]-48)*10 (u1.buf[u1.len-1]-48) ; //杞崲涓烘暣鏁帮紝鍐嶅悎骞?

if(temp<60)sec=temp;

}

}

u1.ok_flag=0;

u1.len=0;

memset(u1.buf,0,256); //娓?

}

*/

// delay_ms(1000);

// cpu_temp= ((1.43 - 3.3/4096*dma_buf[0])/0.0043) 25;

// mq135_val= dma_buf[1]/4096.0*100;

// mq2_val= dma_buf[2]/4096.0*100;

// gz_val= 100-(dma_buf[3]/4096.0*100);

//

// printf("cpu:%.2f 鈩僜r\n",cpu_temp); //

// printf("mq135:%.2f%%\r\n",mq135_val); //

// printf("mq2:%.2f%%\r\n",mq2_val); //

// printf("gz:%.2f%%\r\n",gz_val); //

//dma浣滀笟锛氫娇鐢―ma瀹屾垚澶氶€氶亾鐨勬暟鎹惉杩愶紝dma鎼繍cpu 鍏夋晱 鐑熼浘 鏈夋瘨姘斾綋鏁版嵁

/*

for(i=0;i<3;i ) adc1buf[i]=get_val(adc1, i 1);

adc1buf[0]=adc1buf[0]/4096*100;

adc1buf[1]=adc1buf[1]/4096*100;

adc1buf[2]=100-(adc1buf[2]/4096*100);

printf("cpu:%.2f\r\n",get_cpu_val());

printf("鏈夋瘨姘斾綋:%.2f\r\n",adc1buf[0]); //鍏夌収寮哄害

printf("鐑熼浘鐢茬兎:%.2f\r\n",adc1buf[1]); //鍏夌収寮哄害

printf("鍏夌収:%.2f\r\n",adc1buf[2]); //鍏夌収寮哄害

*/

//浣滀笟1锛氬畬鎴愬厜鐓у己搴︾殑oled 灞忓箷鏄剧ず

//浣滀笟2锛氬畬鎴愮儫闆?鏈夋瘨姘斾綋鐨勬暟鎹噰闆?/p>

//瑕佹眰锛氶噰鐢ㄥ閫氶亾閲囬泦

//cpu娓╁害閲囬泦----adc1_in16

/*

tem=dht11_gettemphumidity(data);

if(tem==0)

{

//printf("閲囬泦鏍¢獙ok\r\n");

shidu=data[0] (data[1]/100.0); //

wendu=data[2] (data[3]/100.0); //31.00-------"31.00"

//printf("娓╁害:%.2f 婀垮害:%.2f\r\n",wendu,shidu);

sprintf(wd_buf,"娓╁害:%.2f",wendu); //杞崲 wd_buf[]="娓╁害:31.00";

sprintf(sd_buf,"婀垮害:%.2f",shidu); //杞崲

oled_show_chinesechar(0,0,wd_buf); //oled鏄剧ず杞崲鏁版嵁

oled_show_chinesechar(0,2,sd_buf);

}

delay_ms(1200);

*/

/*

for(i=0;i<8;i ) //杩炵画鏄剧ず鍥剧墖锛屾瀯鎴恎if

{

oled_showpicture(30,0,94,8,xj[i]); //鏄剧ず鍥剧墖

delay_ms(300);

}

*/

/*

oled_showchinese(0,0,0,16);//涓?/p>

oled_showchinese(18,0,1,16);//鏅?/p>

oled_showchinese(36,0,2,16);//鍥?/p>

oled_showchinese(54,0,3,16);//鐢?/p>

oled_showchinese(72,0,4,16);//瀛?/p>

oled_showchinese(90,0,5,16);//绉?/p>

oled_showchinese(108,0,6,16);//鎶€

oled_showstring(8,16,"zhongjingyuan",16);

oled_showstring(20,32,"2014/05/01",16);

oled_showstring(0,48,"ascii:",16);

oled_showstring(63,48,"code:",16);

oled_showchar(48,48,t,16);//鏄剧ずascii瀛楃

t ;

if(t>'~')t=' ';

oled_shownum(103,48,t,3,16);

oled_refresh();

delay_ms(500);

oled_clear();

oled_showchinese(0,0,0,16); //16*16 涓?/p>

oled_showchinese(16,0,0,24); //24*24 涓?/p>

oled_showchinese(24,20,0,32);//32*32 涓?/p>

oled_showchinese(64,0,0,64); //64*64 涓?/p>

oled_refresh();

delay_ms(500);

oled_clear();

oled_showstring(0,0,"abc",12);//6*12 鈥淎bc鈥?/p>

oled_showstring(0,12,"abc",16);//8*16 鈥淎bc鈥?/p>

oled_showstring(0,28,"abc",24);//12*24 鈥淎bc鈥?/p>

oled_refresh();

delay_ms(500);

oled_scrolldisplay(11,4);

*/

//{

//}

/*

gpio_setbits(gpioc,gpio_pin_3); //杈撳嚭楂樼數骞?-鍏矻ed

delay_ms(500);

gpio_resetbits(gpioc,gpio_pin_3);

delay_ms(500);

if(u1.ok_flag==1) //璇存槑涓插彛鎺ユ敹瀹屾暟鎹?/p>

{

printf("%s",u1.buf); //鍙戦€佷竴涓叉暟鎹埌鐢佃剳鍥炴樉

//娓?

u1.ok_flag=0;

u1.len=0;

memset(u1.buf,0,sizeof(u1.buf));

}

*/

/*

//涓€鐩磋鍋氱殑浜嬫儏

// 鍛煎惛鐏?

for(i=0;i<1500;i ) //娓愪寒

{

gpio_resetbits(gpioc,gpio_pin_5); //杈撳嚭浣庣數骞?/p>

gpio_resetbits(gpiob,gpio_pin_1); //杈撳嚭浣庣數骞?/p>

delay(i);

gpio_setbits(gpioc,gpio_pin_5); //杈撳嚭楂樼數骞?-鍏矻ed

gpio_setbits(gpiob,gpio_pin_1); //杈撳嚭楂樼數骞?-鍏矻ed

delay(1500-i);

}

for(i=0;i<1500;i ) //娓愭殫

{

gpio_resetbits(gpioc,gpio_pin_5); //杈撳嚭浣庣數骞?/p>

gpio_resetbits(gpiob,gpio_pin_1); //杈撳嚭浣庣數骞?/p>

delay(1500-i);

gpio_setbits(gpioc,gpio_pin_5); //杈撳嚭楂樼數骞?-鍏矻ed

gpio_setbits(gpiob,gpio_pin_1); //杈撳嚭楂樼數骞?-鍏矻ed

delay(i);

}

*/

}

}

10銆丳wm

10.1 瀹氫箟

鑴夊啿瀹藉害璋冨埗锛圥wm锛?鏄竴绉嶆暟瀛椾俊鍙凤紝鏈€甯哥敤浜庢帶鍒剁數璺€傝淇″彿鍦ㄩ瀹氫箟鐨勬椂闂村拰閫熷害涓缃负楂橈紙5v鎴?.3v锛夊拰浣庯紙0v锛夈€傞€氬父锛屾垜浠皢pwm鐨勯珮鐢靛钩绉颁负1锛屼綆鐢靛钩涓?

10.2 涓昏鍙傛暟

10.2.1 pwm鍗犵┖姣?/p>

pwm淇″彿淇濇寔楂樼數骞崇殑鏃堕棿鐧惧垎姣旂о涓哄崰绌烘瘮銆傚鏋滀俊鍙峰缁堜负楂樼數骞筹紝鍒欏畠澶勪簬100锛呭崰绌烘瘮锛屽鏋滃畠濮嬬粓澶勪簬浣庣數骞筹紝鍒欏崰绌烘瘮涓?锛呫€俆1涓哄崰绌烘瘮锛孴涓轰竴涓狿wm鍛ㄦ湡銆?/p>

10.2.2 pwm鐨勯鐜嚶?/p>

棰戠巼鍐冲畾pwm瀹屾垚涓€涓懆鏈熺殑閫熷害銆係tm3缂栬瘧鍣ㄤ笂闈㈠彲浠ラ€夋嫨5mhz,10mhz,20mhz鍜?0mhz銆?/p>

10.3 pwm浜х敓鐨勬柟寮?/p>

閫氳繃32鎺у埗鏉匡紝鏈変袱涓柟寮忓彲浠ヤ骇pwm淇″彿锛屼竴涓槸鍒╃敤鏅€氱鍙h緭鍑猴紝鍙︿竴涓氨鏄娇鐢ㄥ畾鏃跺櫒鐨凱wm绔彛鎴栬€呮湇鐢↖o鍙?/p>

10.3.1 鏅€欼o鍙e拰pwm鍙f柟寮忎粙缁?/p>

聽 聽pwm绔彛

stm32 鐨勫畾鏃跺櫒闄や簡 tim6 鍜?7銆傚叾浠栫殑瀹氭椂鍣ㄩ兘鍙互鐢ㄦ潵浜х敓 pwm 杈撳嚭銆傚叾涓珮绾у畾鏃跺櫒 tim1 鍜?tim8 鍙互鍚屾椂浜х敓澶氳揪 7 璺殑 pwm 杈撳嚭銆傝€岄€氱敤瀹氭椂鍣ㄤ篃鑳藉悓鏃朵骇鐢熷杈?4璺殑 pwm 杈撳嚭锛岃繖鏍凤紝stm32 鏈€澶氬彲浠ュ悓鏃朵骇鐢?30 璺?pwm 杈撳嚭銆?/p>

聽 鏅€欼o鍙?/p>

涓€鑸兘澶熻緭鍑篜wm鐨勭鍙i兘浼氬湪涓昏鍔熻兘閭d竴鏍忓嚭鐜癈hx鐨勬爣蹇楋紝鑰屾櫘閫氬畾鏃跺櫒娌℃湁鍑虹幇杩欑鏍囧織銆傚鍥炬墍绀猴紝涓婇潰鐨勭孩妗嗗氨鏄櫘閫氱殑瀹氭椂鍣紝涓嶆槸涓撶敤鐨凱wm绔彛銆偮?/p>

10.4 pwm绋嬪簭

#include "pwm.h" // device header

//led1 pf6--tim10-ch1

void led1_pwm_init(u16 psc,u16 arr)

{

tim_ocinittypedef tim10_pwm; //姣旇緝杈撳嚭

tim_timebaseinittypedef tim10; //鍩烘湰瀹氭椂

gpio_inittypedef led1;

rcc_ahb1periphclockcmd(rcc_ahb1periph_gpiof, enable); //浣胯兘gpioc

rcc_apb2periphclockcmd(rcc_apb2periph_tim10, enable);

gpio_pinafconfig(gpiof,gpio_pinsource6,gpio_af_tim10); //鏄犲皠澶嶇敤涓篢im10_ch1

led1.gpio_mode=gpio_mode_af; //杈撳嚭

led1.gpio_otype=gpio_otype_pp; //鎺ㄦ尳

led1.gpio_pin=gpio_pin_6;

led1.gpio_pupd=gpio_pupd_nopull; //涓婃媺

led1.gpio_speed=gpio_speed_100mhz;

gpio_init(gpiof,&led1);

tim10.tim_clockdivision=tim_ckd_div1; //72m/1=72涓婚

tim10.tim_countermode=tim_countermode_up; //鍚戜笂璁℃暟

tim10.tim_period=arr; //閲嶈杞藉€?/p>

tim10.tim_prescaler=psc-1; //棰勫垎棰?/p>

tim_timebaseinit(tim10, &tim10); //鍒濆鍖栧畾鏃跺櫒3鐨勯厤缃?/p>

tim10_pwm.tim_ocmode=tim_ocmode_pwm1;

tim10_pwm.tim_pulse=0; //姣旇緝瀵勫瓨鍣ㄧ殑鍊硷紝鍏堝啓0锛屽悗闈㈤€氳繃鎵嬪姩璋冪敤鍑芥暟淇敼姣旇緝瀵勫瓨鍣ㄧ殑鍊煎氨鏄慨鏀瑰崰绌烘瘮

tim10_pwm.tim_outputstate=tim_outputstate_enable; //浣胯兘杈撳嚭鎺у埗

tim10_pwm.tim_ocpolarity=tim_ocpolarity_low; //浣庣數骞虫湁鏁?/p>

tim_oc1init(tim10, &tim10_pwm); //鍒濆鍖栨瘮杈冮€氶亾1

tim_oc1preloadconfig(tim10, tim_ocpreload_enable); //浣胯兘閲嶈杞藉€兼瘮杈冨瘎瀛樺櫒

tim_cmd(tim10, enable); //瀹氭椂鍣ㄥ紑濮嬪伐浣?/p>

}

//led2 pf9--tim14-ch1

void led2_pwm_init(u16 psc,u16 arr)

{

tim_ocinittypedef tim14_pwm; //姣旇緝杈撳嚭

tim_timebaseinittypedef tim10; //鍩烘湰瀹氭椂

gpio_inittypedef led1;

rcc_ahb1periphclockcmd(rcc_ahb1periph_gpiof, enable); //浣胯兘gpioc

rcc_apb1periphclockcmd(rcc_apb1periph_tim14, enable);

gpio_pinafconfig(gpiof,gpio_pinsource9,gpio_af_tim14); //鏄犲皠澶嶇敤涓篢im10_ch1

led1.gpio_mode=gpio_mode_af; //杈撳嚭

led1.gpio_otype=gpio_otype_pp; //鎺ㄦ尳

led1.gpio_pin=gpio_pin_9;

led1.gpio_pupd=gpio_pupd_nopull; //涓婃媺

led1.gpio_speed=gpio_speed_100mhz;

gpio_init(gpiof,&led1);

tim10.tim_clockdivision=tim_ckd_div1; //168m/1=168m涓婚

tim10.tim_countermode=tim_countermode_up; //鍚戜笂璁℃暟

tim10.tim_period=arr; //閲嶈杞藉€?/p>

tim10.tim_prescaler=psc-1; //棰勫垎棰?/p>

tim_timebaseinit(tim14, &tim10); //鍒濆鍖栧畾鏃跺櫒3鐨勯厤缃?/p>

tim14_pwm.tim_ocmode=tim_ocmode_pwm1;

tim14_pwm.tim_pulse=0; //姣旇緝瀵勫瓨鍣ㄧ殑鍊硷紝鍏堝啓0锛屽悗闈㈤€氳繃鎵嬪姩璋冪敤鍑芥暟淇敼姣旇緝瀵勫瓨鍣ㄧ殑鍊煎氨鏄慨鏀瑰崰绌烘瘮

tim14_pwm.tim_outputstate=tim_outputstate_enable; //浣胯兘杈撳嚭鎺у埗

tim14_pwm.tim_ocpolarity=tim_ocpolarity_low; //浣庣數骞虫湁鏁?/p>

tim_oc1init(tim14, &tim14_pwm); //鍒濆鍖栨瘮杈冮€氶亾1

tim_oc1preloadconfig(tim14, tim_ocpreload_enable); //浣胯兘閲嶈杞藉€兼瘮杈冨瘎瀛樺櫒

tim_cmd(tim14, enable); //瀹氭椂鍣ㄥ紑濮嬪伐浣?/p>

}

11銆乄25q16/64

11.1 绠€浠?/p>

w25q64鏄负绯荤粺鎻愪緵涓€涓渶灏忕┖闂淬€佹渶灏戝紩鑴氾紝鏈€浣庡姛鑰楃殑涓茶flash瀛樺偍鍣紝25q绯诲垪姣旀櫘閫氱殑涓茶flash瀛樺偍鍣ㄦ洿鐏垫椿锛屾€ц兘鏇翠紭瓒娿€?/p>

w25q64鏀寔鍙屽€?鍥涘€嶇殑spi锛屽彲浠ュ偍瀛樺寘鎷0闊炽€佹枃鏈€佸浘鐗囧拰鍏朵粬鏁版嵁锛涜姱鐗囨敮鎸佺殑宸ヤ綔鐢靛帇 2.7v 鍒?3.6v锛屾甯稿伐浣滄椂鐢垫祦灏忎簬5ma锛屾帀鐢垫椂浣庝簬1ua锛屾墍鏈夎姱鐗囨彁渚涙爣鍑嗙殑灏佽銆偮?/p>

w25q64鐨勫唴瀛樼┖闂寸粨鏋? 聽涓€椤?56瀛楄妭锛?k(4096 瀛楄妭)涓轰竴涓墖鍖猴紝16涓墖鍖轰负1鍧楋紝瀹归噺涓?m瀛楄妭锛屽叡鏈?28涓潡锛?048 涓墖鍖恒€?聽

w25q64姣忛〉澶у皬鐢?56瀛楄妭缁勬垚锛屾瘡椤电殑256瀛楄妭鐢ㄤ竴娆¢〉缂栫▼鎸囦护鍗冲彲瀹屾垚銆?/p>

鎿﹂櫎鎸囦护鍒嗗埆鏀寔: 16椤碉紙1涓墖鍖猴級銆?28椤点€?56椤点€佸叏鐗囨摝闄ゃ€偮?/p>

w25q64鏀寔鏍囧噯涓茶澶栧洿鎺ュ彛锛圫pi锛夛紝鍜岄珮閫熺殑鍙屽€?鍥涘€嶈緭鍑猴紝鍙屽€?鍥涘€嶇敤鐨勫紩鑴氾細涓茶鏃堕挓銆佺墖閫夌銆佷覆琛屾暟鎹?i/o0(di)銆両/o1(do)銆両/o2(wp)鍜?i/o3(hold)銆?spi 鏈€楂樻敮鎸?80mhz锛屽綋鐢ㄥ揩璇诲弻鍊?鍥涘€嶆寚浠ゆ椂锛岀浉褰撲簬鍙屽€嶈緭鍑烘椂鏈€楂橀€熺巼160mhz锛屽洓鍊嶈緭鍑烘椂鏈€楂橀€熺巼 320mhz銆傝繖涓紶杈撻€熺巼姣斿緱涓?浣嶅拰16浣嶇殑骞惰flash瀛樺偍鍣ㄣ€?聽 w25q64鏀寔 jedec 鏍囧噯锛屽叿鏈夊敮涓€鐨?64 浣嶈瘑鍒簭鍒楀彿锛屾柟渚垮尯鍒姱鐗囧瀷鍙?聽

11.1.1 w25q64鑺墖浠嬬粛

鈼廠pi涓茶瀛樺偍鍣ㄧ郴鍒椔犅?聽 -w25q64:64m 浣?8m 瀛楄妭聽聽 聽 -w25q16:16m 浣?2m 瀛楄妭聽聽 聽 -w25q32:32m 浣?4m 瀛楄妭聽聽 聽 -姣?256 瀛楄妭鍙紪绋嬮〉

鈼忕伒娲荤殑4kb鎵囧尯缁撴瀯 聽聽 聽 -缁熶竴鐨勬墖鍖烘摝闄わ紙4k 瀛楄妭锛?聽聽 聽 -鍧楁摝闄わ紙32k 鍜?64k 瀛楄妭锛壜?-涓€娆$紪绋?256 瀛楄妭聽 -鑷冲皯 100,000 鍐?鎿﹂櫎鍛ㄦ湡聽 -鏁版嵁淇濆瓨 20 骞绰?/p>

鈼忔爣鍑嗐€佸弻鍊嶅拰鍥涘€峉pi聽 -鏍囧噯 spi:clk銆丆s銆丏i銆丏o銆乄p銆丠old 聽聽 聽聽聽 聽 -鍙屽€?spi:clk銆丆s銆両o0銆両o1銆乄p銆丠old 聽聽 聽聽聽 聽 -鍥涘€?spi:clk銆丆s銆両o0銆両o1銆両o2銆両o3

鈼忛珮绾х殑瀹夊叏鐗圭偣聽 -杞欢鍜岀‖浠跺啓淇濇姢聽 -閫夋嫨鎵囧尯鍜屽潡淇濇姢聽 -涓€娆℃€х紪绋嬩繚鎶?1)聽 -姣忎釜璁惧鍏锋湁鍞竴鐨?4浣岻d(1)

鈼忛珮鎬ц兘涓茶flash瀛樺偍鍣?聽 聽聽 -姣旀櫘閫氫覆琛孎lash鎬ц兘楂?鍊?聽 聽 聽 聽 聽 -80mhz鏃堕挓棰戠巼 聽 聽 聽 聽 聽 -鍙屽€峉pi鐩稿綋浜?60mhz 聽 聽 聽 聽聽 -鍥涘€峉pi鐩稿綋浜?20mhz 聽 聽 聽 聽聽 -40mb/s杩炵画浼犺緭鏁版嵁 聽 聽聽 -30mb/s闅忔満瀛樺彇锛堟瘡32瀛楄妭锛?聽 聽聽 -姣斿緱涓?6浣嶅苟琛屽瓨鍌ㄥ櫒

鈼忎綆鍔熻€椼€佸娓╁害鑼冨洿聽 -鍗曠數婧?2.7v-3.6v聽 -宸ヤ綔鐢垫祦 4ma锛屾帀鐢?1渭a锛堝吀鍨嬪€硷級 -40鈩冿綖 85鈩冨伐浣?聽

11.2 寮曡剼

濡備笅浠嬬粛鐨勬槸w25q64缂栬憲鐨凷pi鎺ュ彛

11.2.1聽spi鐗囬€夛紙/cs锛夊紩鑴氱敤浜庝娇鑳藉拰绂佹鑺墖鎿嶄綔聽

cs寮曡剼鏄疻25q64鐨勭墖閫夊紩鑴氾紝鐢ㄤ簬閫変腑鑺墖锛涘綋cs涓洪珮鐢靛钩鏃讹紝鑺墖鏈閫夋嫨锛屼覆琛屾暟鎹緭鍑猴紙do銆両o0銆両o1銆両o2 鍜?io3锛夊紩鑴氫负楂橀樆鎬併€傛湭琚€夋嫨鏃讹紝鑺墖澶勪簬寰呮満鐘舵€佷笅鐨勪綆鍔熻€楋紝闄ら潪鑺墖鍐呴儴鍦ㄦ摝闄ゃ€佺紪绋嬨€傚綋/cs 鍙樻垚浣庣數骞筹紝鑺墖鍔熻€楀皢澧為暱鍒版甯稿伐浣滐紝鑳藉浠庤姱鐗囪鍐欐暟鎹€備笂鐢靛悗锛?鍦ㄦ帴鏀舵柊鐨勬寚浠ゅ墠锛?cs 蹇呴』鐢遍珮鍙樹负浣庣數骞炽€備笂鐢靛悗锛?cs 蹇呴』涓婂崌鍒?vcc锛屽湪/cs 鎺ヤ笂鎷夌數闃诲彲浠ュ畬鎴愯繖涓搷浣?聽

11.2.2聽涓茶鏁版嵁杈撳叆銆佽緭鍑哄拰 ios锛圖i銆丏o 鍜?io0銆両o1銆両o2銆両o3锛?/p>

w25q64銆乄25q16 鍜?w25q32 鏀寔鏍囧噯 spi銆佸弻鍊?spi 鍜屽洓鍊?spi銆?/p>

鏍囧噯鐨?spi 浼犺緭鐢ㄥ崟鍚戠殑 di锛堣緭鍏ワ級寮曡剼杩炵画鐨勫啓鍛戒护銆佸湴鍧€鎴栬€呮暟鎹湪涓茶鏃堕挓锛圕lk锛夌殑涓婂崌娌挎椂鍐欏叆鍒拌姱鐗囧唴銆傛爣鍑嗙殑spi 鐢ㄥ崟鍚戠殑 do锛堣緭鍑猴級鍦?clk 鐨勪笅闄嶆部浠庤姱鐗囧唴璇诲嚭鏁版嵁鎴栫姸鎬併€?/p>

11.2.3 鍐欎繚鎶わ紙/wp锛?/p>

鍐欎繚鎶ゅ紩鑴氾紙/wp锛夌敤鏉ヤ繚鎶ょ姸鎬佸瘎瀛樺櫒銆傚拰鐘舵€佸瘎瀛樺櫒鐨勫潡淇濇姢浣嶏紙sec銆乀b銆丅p2銆丅p1 鍜孊p0锛夊拰鐘舵€佸瘎瀛樺櫒淇濇姢浣嶏紙srp锛夊瀛樺偍鍣ㄨ繘琛屼竴閮ㄥ垎鎴栬€呭叏閮ㄧ殑纭欢淇濇姢銆?wp 寮曡剼浣庣數骞虫湁鏁堛€傚綋鐘舵€佸瘎瀛樺櫒 2 鐨?qe 浣嶈缃綅浜嗭紝/wp 寮曡剼锛堢‖浠跺啓淇濇姢锛夌殑鍔熻兘涓嶅彲鐢ㄣ€?/p>

11.2.4 涓茶鏃堕挓锛圕lk锛?/p>

涓茶鏃堕挓杈撳叆寮曡剼涓轰覆琛岃緭鍏ュ拰杈撳嚭鎿嶄綔鎻愪緵鏃跺簭

11.3 w25q64鏍囧噯鐨凷pi鎿嶄綔

w25q64鏍囧噯spi鎬荤嚎鎺ュ彛鍖呭惈鍥涗釜淇″彿: 涓茶鏃堕挓锛圕lk锛夈€佺墖閫夌锛?cs锛夈€佷覆琛屾暟鎹緭鍏ワ紙di锛夊拰涓茶鏁版嵁杈撳嚭锛圖o锛夈€?/p>

di杈撳叆寮曡剼鍦–lk鐨勪笂鍗囨部杩炵画鍐欏懡浠ゃ€佸湴鍧€鎴栨暟鎹埌鑺墖鍐呫€?/p>

do杈撳嚭寮曡剼鍦–lk鐨勪笅闄嶆部浠庤姱鐗囧唴璇诲嚭鏁版嵁鎴栫姸鎬併€?/p>

w25q64鍒嗗埆鏀寔spi鎬荤嚎宸ヤ綔妯″紡0鍜屽伐浣滄ā寮?銆傛ā寮?鍜屾ā寮?鐨勪富瑕佸尯鍒湪浜庡父鎬佹椂鐨凜lk淇″彿涓嶅悓锛涘浜庢ā寮?鏉ヨ锛屽綋spi涓绘満宸插噯澶囧ソ鏁版嵁杩樻病浼犺緭鍒颁覆琛孎lash涓椂锛孋lk淇″彿甯告€佷负浣庯紱

璁惧鏁版嵁浼犺緭鏄粠楂樹綅寮€濮嬶紝鏁版嵁浼犺緭鐨勬牸寮忎负8bit锛屾暟鎹噰鏍蜂粠绗簩涓椂闂磋竟娌垮紑濮嬶紝绌洪棽鐘舵€佹椂锛屾椂閽熺嚎clk涓洪珮鐢靛钩銆?聽

11.4 w25q瀹炰緥浠g爜

#include "w25q64.h" // device header

void w25q64_spi1_init(void)

{

gpio_inittypedef gpio_initstructure;

spi_inittypedef w25q64_spi1;

rcc_ahb1periphclockcmd(rcc_ahb1periph_gpiob, enable); //浣胯兘gpiob

rcc_apb2periphclockcmd(rcc_apb2periph_spi1, enable);

//pb3:sck pb4:miso pb5:mosi

gpio_pinafconfig(gpiob, gpio_pinsource3, gpio_af_spi1);

gpio_pinafconfig(gpiob, gpio_pinsource4, gpio_af_spi1);

gpio_pinafconfig(gpiob, gpio_pinsource5, gpio_af_spi1);

gpio_initstructure.gpio_mode=gpio_mode_af; //杈撳嚭

gpio_initstructure.gpio_otype=gpio_otype_pp; //鎺ㄦ尳

gpio_initstructure.gpio_pin=gpio_pin_3|gpio_pin_4|gpio_pin_5;

gpio_initstructure.gpio_pupd=gpio_pupd_up; //涓婃媺

gpio_initstructure.gpio_speed=gpio_speed_100mhz;

gpio_init(gpiob,&gpio_initstructure);

//pb14:cs

gpio_initstructure.gpio_mode=gpio_mode_out; //杈撳嚭

gpio_initstructure.gpio_otype=gpio_otype_pp; //鎺ㄦ尳

gpio_initstructure.gpio_pin=gpio_pin_14;

gpio_initstructure.gpio_pupd=gpio_pupd_up; //涓婃媺

gpio_initstructure.gpio_speed=gpio_speed_100mhz;

gpio_init(gpiob,&gpio_initstructure);

gpio_setbits(gpiob,gpio_pin_14); //榛樿杈撳嚭楂樼數骞?

//鍒濆鍖朣pi1

w25q64_spi1.spi_baudrateprescaler = spi_baudrateprescaler_8; //8鍒嗛锛?68/8=21mhz

w25q64_spi1.spi_cpha=spi_cpha_2edge; //绗簩涓椂閽熸部閲囬泦鏁版嵁

w25q64_spi1.spi_cpol=spi_cpol_high; //榛樿涓洪珮鐢靛钩

w25q64_spi1.spi_crcpolynomial= 7; //crc鍥哄畾涓?

w25q64_spi1.spi_datasize=spi_datasize_8b; //8浣嶆暟鎹?/p>

w25q64_spi1.spi_direction=spi_direction_2lines_fullduplex; //鍏ㄥ弻宸ュ弻鍚?/p>

w25q64_spi1.spi_firstbit=spi_firstbit_msb; //楂樹綅鍏堝彂

w25q64_spi1.spi_mode=spi_mode_master; //涓绘満妯″紡

w25q64_spi1.spi_nss=spi_nss_soft; //spi_nss_soft锛岃蒋浠舵帶鍒讹紝gpio鎺у埗鐗囬€夋媺楂樻媺浣?/p>

spi_init( spi1, &w25q64_spi1);

spi_cmd(spi1,enable); //浣胯兘spi1寮€濮嬪伐浣?/p>

}

//鍙戦€佷竴涓瓧鑺傛暟鎹?/p>

void spi1_sendbyte(char data)

{

while(!(spi_i2s_getflagstatus(spi1,spi_i2s_flag_txe))); //绛夊緟涓虹┖

spi_i2s_senddata(spi1,data); //鍙戦€佹暟鎹?/p>

}

//鎺ユ敹涓€涓瓧鑺傛暟鎹?/p>

char spi1_readbyte(void)

{

while(!(spi_i2s_getflagstatus(spi1,spi_i2s_flag_rxne))); //鍒ゆ柇闈炵┖

spi_i2s_receivedata(spi1);

}

/********************************************************************

鍑芥暟鍔熻兘锛歋pi1鍙戦€佹垨鎺ユ敹1涓瓧鑺傜殑瀛楃鏁版嵁

鍙傛暟1锛歞ata锛氫綘瑕佸彂閫佺殑鏁版嵁

杩斿洖鍊硷細鎺ユ敹鍒扮殑鏁版嵁

璇存槑锛氫綘瑕佸彂閫佷竴涓瓧鑺傛暟鎹嚭鍘荤殑鍚屾椂锛屼篃浼氭帴鏀跺緱鍒颁竴涓棤鐢ㄧ殑瀛楄妭鏁版嵁

浣犺鎺ユ敹涓€涓瓧鑺傛暟鎹悓鏃讹紝涔熻鍙戦€佷竴涓棤鐢ㄧ殑瀛楄妭鏁版嵁鍑哄幓

********************************************************************/

char spi1_sendreadbyte(char data)

{

while(!(spi_i2s_getflagstatus(spi1,spi_i2s_flag_txe))); //绛夊緟涓虹┖

spi_i2s_senddata(spi1,data); //鍙戦€佹暟鎹?/p>

while(!(spi_i2s_getflagstatus(spi1,spi_i2s_flag_rxne))); //鍒ゆ柇闈炵┖

spi_i2s_receivedata(spi1);

}

/********************************************************************

鍑芥暟鍔熻兘锛歐25q64鍐欎娇鑳?/p>

鍙傛暟1锛氭棤

鍙傛暟2锛氭棤

杩斿洖鍊硷細鏃?/p>

浣滆€咃細xxx

********************************************************************/

void w25q64_writeenable(void)

{

cs=0; //鐗囬€夋媺浣?/p>

spi1_sendreadbyte(0x06);//鍙戦€佸啓浣胯兘鎸囦护

cs=1;//鐗囬€夋媺楂?/p>

}

/********************************************************************

鍑芥暟鍔熻兘锛氳鑺墖id

鍙傛暟1锛欼d锛氬瓨鍌ㄦ暟鎹殑鍏ュ彛鍦板潃锛岀0瀛楄妭涓虹敓浜d锛岀1瀛楄妭涓哄櫒浠禝d

鍙傛暟2锛氭棤

杩斿洖鍊硷細鏃?/p>

w25q16:0xef14

w25q32:0xef15

w25q64:0xef16

w25q128:0xef17

********************************************************************/

void w25q64_readid(u8 *id)

{

cs=0; //鐗囬€夋媺浣?/p>

spi1_sendreadbyte(0x90);//鍙戦€佽鍣ㄤ欢id

spi1_sendreadbyte(0x00);//鍙戦€?4浣嶅湴鍧€

spi1_sendreadbyte(0x00);//鍙戦€?4浣嶅湴鍧€

spi1_sendreadbyte(0x00);//鍙戦€?4浣嶅湴鍧€

id[0]=spi1_sendreadbyte(0xff);//鎺ユ敹涓€涓瓧鑺傜敓浜d锛岀殑鍚屾椂鍙戦€佷竴涓棤鐢ㄦ暟鎹?/p>

id[1]=spi1_sendreadbyte(0xff);//鎺ユ敹涓€涓瓧鑺傚櫒浠禝d锛岀殑鍚屾椂鍙戦€佷竴涓棤鐢ㄦ暟鎹?/p>

cs=1; //鐗囬€夋媺浣?/p>

}

/********************************************************************

鍑芥暟鍔熻兘锛氳鐘舵€佸€?/p>

鍙傛暟1锛氭棤

鍙傛暟2锛氭棤

杩斿洖鍊硷細鐘舵€佺殑鍊?/p>

浣滆€咃細xxx

********************************************************************/

u8 w25q64_readbusy(void)

{

u8 busy=0xff;

cs=0; //鐗囬€夋媺浣?/p>

spi1_sendreadbyte(0x05);//鍙戦€佽鐘舵€佹寚浠?x05

busy=spi1_sendreadbyte(0xff);//璇诲彇鐘舵€佸€?/p>

cs=1; //鐗囬€夋媺楂?/p>

return busy;

}

/********************************************************************

鍑芥暟鍔熻兘锛氭摝闄よ姱鐗?/p>

鍙傛暟1锛氭棤

鍙傛暟2锛氭棤

杩斿洖鍊硷細鏃?/p>

璇存槑锛氭摝闄ゆ椂闂村ぇ姒?s

********************************************************************/

void w25q64_deletechip(void)

{

w25q64_writeenable(); //鍐欎娇鑳?/p>

cs=0; //鐗囬€夋媺浣?/p>

spi1_sendreadbyte(0xc7);//鍙戦€佹摝闄よ姱鐗囨寚浠?xc7

cs=1; //鐗囬€夋媺楂橈紝缁撴潫

while((w25q64_readbusy() & 1<<0)); //绛夊緟busy浣嶄负0,璇存槑鎿﹂櫎瀹屾瘯锛屽苟閫€鍑?

}

/********************************************************************

鍑芥暟鍔熻兘锛氬潡鎿﹂櫎

鍙傛暟1锛氭棤

鍙傛暟2锛氭棤

杩斿洖鍊硷細鏃?/p>

璇存槑锛氭摝闄ゆ椂闂村ぇ姒?s

********************************************************************/

void w25q64_deleteblock(u8 block)

{

u32 addr=block*65536; //绠楀嚭鎿﹂櫎鍧楃殑璧峰鍦板潃

w25q64_writeenable(); //鍐欎娇鑳?/p>

cs=0; //鐗囬€夋媺浣?/p>

spi1_sendreadbyte(0xd8);//鍙戦€佸潡鎿﹂櫎鎸囦护

spi1_sendreadbyte((u8)(addr>>16)); //鍙戦€佸湴鍧€鐨勯珮8浣?/p>

spi1_sendreadbyte((u8)(addr>>8)); //鍙戦€佸湴鍧€鐨勪腑8浣?/p>

spi1_sendreadbyte((u8)addr); //鍙戦€佸湴鍧€鐨勪綆8浣?/p>

cs=1; //鐗囬€夋媺楂橈紝缁撴潫

while((w25q64_readbusy() & 1<<0)); //绛夊緟busy浣嶄负0,璇存槑鎿﹂櫎瀹屾瘯锛屽苟閫€鍑?

}

/********************************************************************

鍑芥暟鍔熻兘锛氭摝闄や竴涓墖鍖猴紝涓€鍏辨湁32鍧?16鎵囧尯=512鎵囧尯

鍙傛暟1锛氭棤

鍙傛暟2锛氭棤

杩斿洖鍊硷細鏃?/p>

璇存槑锛氭摝闄ゆ椂闂村ぇ姒?s

********************************************************************/

void w25q64_deletesector(u16 sector)

{

u32 addr=sector*4096; //绠楀嚭鎿﹂櫎鎵囧尯璧峰鍦板潃

w25q64_writeenable(); //鍐欎娇鑳?/p>

cs=0; //鐗囬€夋媺浣?/p>

spi1_sendreadbyte(0x20);//鍙戦€佹墖鍖烘摝闄ゆ寚浠?/p>

spi1_sendreadbyte((u8)(addr>>16)); //鍙戦€佸湴鍧€鐨勯珮8浣?/p>

spi1_sendreadbyte((u8)(addr>>8)); //鍙戦€佸湴鍧€鐨勪腑8浣?/p>

spi1_sendreadbyte((u8)addr); //鍙戦€佸湴鍧€鐨勪綆8浣?/p>

cs=1; //鐗囬€夋媺楂橈紝缁撴潫

while((w25q64_readbusy() & 1<<0)); //绛夊緟busy浣嶄负0,璇存槑鎿﹂櫎瀹屾瘯锛屽苟閫€鍑?

}

/********************************************************************

鍑芥暟鍔熻兘锛氶〉缂栫▼鍐欏叆鏁版嵁锛屼笉鑳借法椤电紪绋嬶紝娌℃湁甯︽摝闄ゅ唴瀛樺姛鑳?/p>

鍙傛暟1锛歞ata:鍐欏叆鏁版嵁鐨勯鍦板潃

鍙傛暟2锛歛ddr锛氭暟鎹啓鍏ョ殑鍦板潃浣嶇疆

鍙傛暟3锛歭en锛氭暟鎹啓鍏ョ殑涓暟

杩斿洖鍊硷細鏃?/p>

璇存槑锛氭渶澶氬彲浠ュ啓鍏?56涓瓧鑺?/p>

********************************************************************/

void w25q64_pagewritenoturn(u8 *data,u32 addr,u16 len)

{

while((w25q64_readbusy() & 1<<0)); //鍒ゆ柇鑺墖鏄惁涓哄繖

w25q64_writeenable(); //鍐欎娇鑳?/p>

cs=0; //鐗囬€夋媺浣?/p>

spi1_sendreadbyte(0x02);//鍙戦€侀〉缂栫▼鎸囦护0x02

spi1_sendreadbyte((u8)(addr>>16)); //鍙戦€佸湴鍧€鐨勯珮8浣?/p>

spi1_sendreadbyte((u8)(addr>>8)); //鍙戦€佸湴鍧€鐨勪腑8浣?/p>

spi1_sendreadbyte((u8)addr); //鍙戦€佸湴鍧€鐨勪綆8浣?/p>

while(len) //寰幆鍐欏叆

{

spi1_sendreadbyte(*data ); //鍙戦€佸湴鍧€鐨勯珮8浣?

len--; //鍐欏叆涓€涓瓧鑺傦紝鏁伴噺鍑?

}

cs=1; //鐗囬€夋媺楂橈紝缁撴潫

while((w25q64_readbusy() & 1<<0)); //绛夊緟鑺墖涓轰笉蹇欙紝璇存槑绌洪棽浜嗭紝鍐欏叆鏁版嵁瀹屾垚

}

/********************************************************************

鍑芥暟鍔熻兘锛氶〉缂栫▼鍐欏叆鏁版嵁锛屽彲浠ヨ法椤电紪绋嬶紝娌℃湁甯︽摝闄ゅ唴瀛樺姛鑳?/p>

鍙傛暟1锛歞ata:鍐欏叆鏁版嵁鐨勯鍦板潃

鍙傛暟2锛歛ddr锛氭暟鎹啓鍏ョ殑鍦板潃浣嶇疆

鍙傛暟3锛歭en锛氭暟鎹啓鍏ョ殑涓暟

杩斿洖鍊硷細鏃?/p>

璇存槑锛氭渶澶氬彲浠ュ啓鍏?56涓瓧鑺?/p>

********************************************************************/

void w25q64_pagewrite_next_nodelete(u8 *data,u32 addr,u32 len)

{

u32 address_sum=addr; //璧峰鍦板潃

int i;

u32 ago_num=256-(addr%6); //绠楀嚭鍓嶄竴椤甸渶瑕佸~鍏呭畬鐨勬暟閲?

u32 sum=len-ago_num; //鍐欏叆鎬绘暟鍑忓幓鍓嶉潰涓€椤靛啓鐨勬暟閲忥紝鍓╀笅闇€瑕佺户缁啓鐨勬€绘暟

u32 zs_page=sum/256; //寰楀埌鍓╀笅鎬绘暟鐨勬暣鍊嶉〉鏁?/p>

u32 ys=sum%6; //鍐欏畬鏁撮〉锛屽墿涓嬩笉婊′竴椤电殑浣欐暟

//1銆佸厛鍐欐弧鍓嶄竴椤?/p>

w25q64_pagewritenoturn(data,addr,ago_num);

address_sum =ago_num; //鍦板潃澧炲姞

data =ago_num; //鍐欏叆鐨勬暟鎹闅忕潃鍦板潃涓€璧峰鍔?/p>

//2銆佸啀鍐欐暣鍊嶉〉

for(i=0;i

{

//鎸囬拡鎸囧悜鏁版嵁涔熻涓€璧疯法椤?/p>

w25q64_pagewritenoturn(data,address_sum,256); //鍐欐弧椤?

data =256;

address_sum =256; //璁$畻宸插啓鐨勫湴鍧€鏁伴噺

}

//3銆佹渶鍚庡啓瀹屾暣椤碉紝鍓╀笅涓嶆弧涓€椤电殑浣欐暟

w25q64_pagewritenoturn(data,address_sum,ys);

}

///********************************************************************

//鍑芥暟鍔熻兘锛氶〉缂栫▼鍐欏叆鏁版嵁锛屽彲浠ヨ法椤电紪绋嬶紝娌℃湁甯︽摝闄ゅ唴瀛樺姛鑳?/p>

//鍙傛暟1锛歞ata:鍐欏叆鏁版嵁鐨勯鍦板潃

//鍙傛暟2锛歛ddr锛氭暟鎹啓鍏ョ殑鍦板潃浣嶇疆

//鍙傛暟3锛歭en锛氭暟鎹啓鍏ョ殑涓暟

//杩斿洖鍊硷細鏃?/p>

//璇存槑锛氭渶澶氬彲浠ュ啓鍏?56涓瓧鑺?/p>

//********************************************************************/

//void w25q64_pagewrite_next_nodelete(u8 *data,u32 addr,u32 len)

//{

// u32 address_sum=addr; //璧峰鍦板潃

// int i;

//

// u32 ago_num=256-(addr%6); //绠楀嚭鍓嶄竴椤甸渶瑕佸~鍏呭畬鐨勬暟閲?

// u32 sum=len-ago_num; //鍐欏叆鎬绘暟鍑忓幓鍓嶉潰涓€椤靛啓鐨勬暟閲忥紝鍓╀笅闇€瑕佺户缁啓鐨勬€绘暟

// u32 zs_page=sum/256; //寰楀埌鍓╀笅鎬绘暟鐨勬暣鍊嶉〉鏁?/p>

// u32 ys=sum%6; //鍐欏畬鏁撮〉锛屽墿涓嬩笉婊′竴椤电殑浣欐暟

//

// //1銆佸厛鍐欐弧鍓嶄竴椤?/p>

// w25q64_pagewritenoturn(data,addr,ago_num);

// address_sum =ago_num; //鍦板潃澧炲姞

// data =ago_num; //鍐欏叆鐨勬暟鎹闅忕潃鍦板潃涓€璧峰鍔?/p>

//

// //2銆佸啀鍐欐暣鍊嶉〉

// for(i=0;i

// {

// //鎸囬拡鎸囧悜鏁版嵁涔熻涓€璧疯法椤?/p>

// w25q64_pagewritenoturn(data,address_sum,256); //鍐欐弧椤?

// data =256;

// address_sum =256; //璁$畻宸插啓鐨勫湴鍧€鏁伴噺

// }

// //3銆佹渶鍚庡啓瀹屾暣椤碉紝鍓╀笅涓嶆弧涓€椤电殑浣欐暟

// w25q64_pagewritenoturn(data,address_sum,ys);

//

//}

/********************************************************************

鍑芥暟鍔熻兘锛氳鏁版嵁

鍙傛暟1锛歞ata: 璇诲埌鏁版嵁瀛樻斁鐨勯鍦板潃

鍙傛暟2锛歛ddr锛氫粠w25q64璇绘暟鎹殑璧峰鍦板潃

鍙傛暟3锛歭en锛氳鍙栨暟鎹殑涓暟

杩斿洖鍊硷細鏃?/p>

浣滆€咃細xxx

********************************************************************/

void w25q64_readdata(u8 *data,u32 addr,u16 len)

{

w25q64_writeenable(); //鍐欎娇鑳?/p>

cs=0; //鐗囬€夋媺浣?/p>

spi1_sendreadbyte(0x03);//鍙戦€佽鏁版嵁鎸囦护0x03

spi1_sendreadbyte(addr>>16); //鍙戦€佸湴鍧€鐨勯珮8浣?/p>

spi1_sendreadbyte(addr>>8); //鍙戦€佸湴鍧€鐨勪腑8浣?/p>

spi1_sendreadbyte(addr); //鍙戦€佸湴鍧€鐨勪綆8浣?/p>

while(len) //寰幆鍐欏叆

{

*data =spi1_sendreadbyte(0xff); //鍙戦€佸湴鍧€鐨勯珮8浣?

len--; //璇诲彇鐨勫瓧鑺傛暟閲忥紝姣忚涓€涓紝鏁伴噺鍑?

}

*data='\0'; //娣诲姞鏁版嵁缁撴潫绗?/p>

cs=1; //鐗囬€夋媺楂橈紝缁撴潫

}

12.瑙︽懜灞?/p>

聽12.1瀹炵墿鍥?/p>

12.2 瑙︽懜灞忕绫诲垎绫?/p>

聽 聽12.2.1 鐢甸樆寮忓睆骞?/p>

鐗圭偣锛氬畾浣嶅噯纭笖鍙互瀹炵幇鍗曠偣瑙︽懜锛涚數闃诲紡灞忓箷鏄竴绉嶄紶鎰熷櫒锛屽畠灏嗙煩褰㈠尯鍩熺殑瑙︽懜鐐圭殑鐗╃悊浣嶇疆杞崲涓轰唬琛╔/y杞寸殑鐢靛帇锛岀幇鍦ㄥ緢澶氱殑lcd灞忓箷閮芥槸閲囩敤浜嗙數闃诲紡鐨勮е鎽稿睆锛岃繖绉嶅睆骞曞彲浠ョ敤5銆?銆?銆?绾挎潵浜х敓鍋忕疆鐢靛帇锛屽悓鏃跺彲浠ヨ鍥炶е鎽哥偣鐨勭數鍘嬨€?/p>

鐢甸樆寮忚е鎽稿睆鏄竴绉嶄紶鎰熷櫒锛屽熀鏈笂鏄杽鑶滃姞涓婄幓鐠冪殑缁撴瀯锛岃杽鑶滃拰鐜荤拑鐩搁偦鐨勪竴闈笂鍧囨秱鏈塈to锛堢撼绫抽摕閿¢噾灞炴哀鍖栫墿锛夋秱灞傦紝ito鍏锋湁寰堝ソ鐨勫鐢垫€у拰閫忔槑鎬с€傚綋瑙︽懜鎿嶄綔鏃讹紝钖勮啘涓嬪眰鐨処to浼氭帴瑙﹀埌鐜荤拑涓婂眰鐨処to锛岀粡鐢辨劅搴斿櫒浼犲嚭鐩稿簲鐨勭數淇″彿锛岀粡杩囪浆鎹㈢數璺€佸埌澶勭悊鍣紝閫氳繃杩愮畻杞寲涓哄睆骞曚笂鐨刋銆乊鍊硷紝鑰屽畬鎴愮偣閫夌殑鍔ㄤ綔锛屽苟鍛堢幇鍦ㄥ睆骞曚笂銆?/p>

鍏朵紭缂虹偣涔熷緢鏄庢樉锛岀己鐐规槸浠栧彧鑳芥敮鎸佸崟鐐硅е鎽革紝涓嶈兘瀹炵幇澶氱偣瑙﹀彂瑙︽懜鍔熻兘锛涗絾鏄敱浜庤繖涓崟鐐硅е鎽哥殑鐗圭偣锛屼娇寰楀畠瑙︽懜鐨勭簿搴﹀緢楂樸€?/p>

12.2.2 鐢垫劅寮忚е鎽稿睆

鏀寔澶氱偣瑙︽懜锛屼环鏍煎亸璐点€傚伐涓氬簲鐢ㄦ渶骞挎硾锛屾垜浠幇鍦ㄥ競闈笂鐨勬墜鏈洪兘鏄劅搴斿紡鐨勮е鎽稿睆锛屽畠鐨勪紭缂虹偣鏄窡鐢甸樆寮忕殑瑙︽懜灞忕浉鍙嶏紝浼樼偣鏄彲浠ュ疄鐜板鐐规劅搴旓紝鑰岀己鐐瑰氨鏄簿搴︽病閭d箞楂樸€?/p>

聽聽

聽12.2.3 绾㈠绾垮紡

鐗圭偣鏄細浠锋牸鍗佸垎浣庡粔锛屼絾鍏跺妗嗘槗纰庯紝瀹规槗浜х敓鍏夊共鎵帮紝鏇查潰鎯呭喌涓嬪け鐪燂紝鎵€浠ヤ竴鑸儏鍐典笅鎴戜滑涓嶄細閫夋嫨杩欐牱鐨勮е鎽稿睆銆傝繖涓竴鑸敤鍦ㄧ壒娈婄殑宸ヨ壓銆?/p>

12.2.4 琛ㄩ潰澹版尝寮?/p>

鐗圭偣鏄細鍙互瑙e喅鍚勭缂虹偣锛屼絾鏄睆骞曡〃闈㈠鏋滄湁姘存淮鍜屽皹鍦熶細浣胯е鎽稿睆鍙樼殑杩熼挐銆?/p>

12.3 xpt2046閲囬泦瑙︽懜ad鑺墖

聽 聽12.3.1 瑙︽懜灞忔帴鍙h繛鎺ュ師鐞?/p>

12.3.2 xpt2046鐗规€?/p>

宸ヤ綔鐢靛帇鑼冨洿涓?.2v-5.25v,鏀寔1.5v~5.25v鐨勬暟瀛桰o鍙?鍐呭缓2.5v鍙傝€冪數鍘嬫簮锛?鐢垫簮鐢靛帇娴嬮噺锛?v-6v)鍐呭缓缁撴俯娴嬮噺鍔熻兘瑙︽懜鍘嬪姏娴嬮噺; 閲囩敤spi3绾挎帶鍒堕€氫俊鎺ュ彛涓旀湁鑷姩power-down鍔熻兘; 灏佽:qpn-16.tssop-16鍜孷fbga-48涓嶵sc2046銆丄k4182a瀹屽叏鍏煎

12.3.3 xpt2046缁撴瀯鍘熺悊

聽12.3.4 xpt2046寮曡剼

灞忓箷x/y鍧愭爣鐨勮緭鍏?/-绔?/p>

聽搴旂敤寮曡剼

聽12.3.5 浣跨敤鍒扮殑寮曡剼

鐪嬪師鐞嗗浘锛屾垜浠煡閬擄紝鏈夌孩妗嗗湀璧锋潵鐨勫紩鑴氳鐢ㄦ垜浠繘琛岄厤缃細

t_miso聽 pb2 寮曡剼

聽 聽 聽 聽 xpt2046鐨勪覆琛屾暟鎹緭鍑虹銆係tm32鐨勬暟鎹緭鍏ョ锛屾暟鎹湪dclk鐨勪笅闄嶆部聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽绉诲嚭锛屽綋cs楂樼數骞虫椂涓洪珮闃荤姸鎬侊紝閰嶇疆涓鸿緭鍏ユā寮忥紝绌洪棽涓洪珮銆?/p>

t_pen聽 聽pb1寮曡剼

聽 聽 聽 聽绗斾腑鏂緭鍑猴紝閰嶇疆涓鸿緭鍏ユā寮忥紝绌洪棽妯″紡涓洪珮鐢靛钩锛?/p>

t_cs聽 聽 聽pc13寮曡剼

聽 聽 聽鐗囬€変俊鍙枫€傛帶鍒惰浆鎹㈡椂搴忓拰浣胯兘涓茶杈撳叆杈撳嚭瀵勫瓨鍣紝楂樼數骞虫椂adc鎺夌數锛?/p>

t_mosi聽 聽pf11寮曡剼

聽 聽 聽xpt2046鐨勪覆琛屾暟鎹緭鍏ョ锛孲tm32鐨勮緭鍑虹锛屽綋cs涓轰綆鐢靛钩鏃讹紝鏁版嵁鍦―clk涓婂崌娌块攣瀛樿繘鏉ワ紱

t_sck聽 聽pb0寮曡剼

聽 聽 聽聽xpt2046澶栭儴鏃堕挓淇″彿杈撳叆锛孲tm32鐨勬椂閽熶俊鍙疯緭鍑猴紱

灏忕粨

聽 stm32鍙戞暟鎹殑鏃跺€欙紝鐗囬€夋媺浣庯紝dclk鎷夐珮锛屾妸鏁版嵁閿佸瓨鍦═_mosi寮曡剼浼犺緭鍑哄幓锛涘綋stm32璇绘暟鎹殑鏃跺€欙紝鐗囬€夋媺浣庯紝dclk鎷変綆锛岃鍙朤_miso鐢靛钩鐘舵€併€?/p>

12.4 xpt2046鎺у埗璇存槑

12.4.1 鍗曠杩樻槸宸垎妯″紡

閫夋嫨vbat銆?temp鍜孉ux鏃跺彲浠ラ厤缃负鍗曠妯″紡锛屼綔涓鸿е鎽稿睆搴旂敤鏃讹紝鍙互閰嶇疆涓哄樊鍒嗘ā寮忥紝杩欏彲鏈夋晥娑堥櫎鐢变簬椹卞姩寮€鍏崇殑瀵勭敓鐢甸樆鍙婂閮ㄧ殑骞叉壈甯︽潵鐨勬祴閲忚宸紝鎻愰珮杞崲鍑嗙‘ 搴︺€?/p>

12.4.2 绗斾腑鏂緭鍑?/p>

鏈変汉鎸変笅灞忓箷鏃讹紝瑙︽懜灞忎笅鎷夊埌鍦帮紝涔熷氨鏄寜涓嬩负浣庣數骞?/p>

12.4.3 鎺у埗瀛楄妭

鐢ㄤ簬閫夋嫨閲囬泦鐨勬槸x杩樻槸y杞寸殑ad鍊硷紝浣滅敤锛氭帶鍒跺瓧鑺傜敱 din 杈撳叆鐨勬帶鍒跺瓧濡傝〃 3 鎵€绀猴紝瀹冪敤鏉ュ惎鍔ㄨ浆鎹紝瀵诲潃锛岃缃?adc 鍒嗚鲸鐜囷紝閰嶇疆鍜屽 xpt2046 杩涜鎺夌數鎺?鍒躲€?/p>

12.5 浠g爜瀹炰緥

聽鎵弿瑙︽懜灞?/p>

touch锛氬瓨鏀捐鍙栧埌鐨剎/y鍧愭爣鍊硷紝杩?鍥?鍊?: 0锛氭湁鎸変笅锛?锛氭棤鎸変笅

********************************************************************************/

unsigned char xpt2046_scantouch(touch_typedef *touch)

{

touch_typedef ad;

unsigned char ucretvaule;

if(t_pen == 0)

{ //鍒ゆ柇瑙︽懜灞忔湁娌℃湁琚寜涓?/p>

if(t_pen == 0)

{

xpt2046_readxyad(&ad);

touch->xval = ad.xval * kx bx;

touch->yval = ad.yval * ky by;

ucretvaule = 0;

}

}

else

{

touch->xval=0xffff;

touch->yval=0xffff;

ucretvaule = 1;

}

return ucretvaule;

}

璇诲彇x/y杞碅d鍊硷紝骞舵护娉㈠鐞?/p>

void xpt2046_readxyad(touch_typedef *touch)

{

unsigned char i, j;

unsigned short adx[5], ady[5];

unsigned short temp;

for(i=0; i<5; i ){ //鍏堥噰闆嗗娆℃暟鎹?/p>

adx[i] = xpt2046_readad(0xd0);

ady[i] = xpt2046_readad(0x90);

}

for(i=0; i<5; i )

{ //鍏堟帓搴忥紝鎵惧嚭鏈€澶у拰鏈€灏忕殑鍊?/p>

for(j=0; j<5-i-1; j )

{

if(adx[j] > adx[j 1])

{

temp = adx[j];

adx[j] = adx[j 1];

adx[j 1] = temp;

}

if(ady[j] > ady[j 1])

{

temp = ady[j];

ady[j] = ady[j 1];

ady[j 1] = temp;

}

}

}

touch->xval = adx[2];

touch->yval = ady[2];

}

璇诲彇杞碅d鍊?/p>

unsigned short xpt2046_readad(unsigned char cmd)

{

unsigned char vh, vl;

t_cs = 0; //鎷変綆鐗囬€夛紝閫変腑鍣ㄤ欢锛屽紑濮嬮€氫俊

xpt2046_writebyte(cmd); //鍙戦€佹祴閲忓懡浠?/p>

delay_us(1); //绛夊埌鑺墖蹇欑粨鏉?/p>

vh = xpt2046_readbyte();//璇诲彇鏁版嵁鐨勯珮浣?/p>

vl = xpt2046_readbyte();//璇诲彇鏁版嵁鐨勪綆浣?/p>

t_cs = 1; //鎷変綆鐗囬€夛紝鍙栨秷閫変腑锛岀粨鏉熼€氫俊

return ((vh<<8|vl)>>4); //杩斿洖缁撴灉锛屽叾涓彧鏈?2浣嶆湁鏁?/p>

}

瑙︽懜灞忔牎鍑嗗嚱鏁?/p>

杩欎釜鍙互閫氱敤锛岄渶瑕佺殑鐩存帴澶嶅埗灏卞ソ浜?/p>

void xpt2046_touchadjust(void)

{

unsigned short lcd_pos[4][2] = {20, 20, 300, 20, 20, 460, 300, 460, };

touch_typedef touch_pos[4]; //鐢ㄦ潵瀛樻斁x,y鐨?涓狝d鍊?/p>

unsigned char i, j;

double len1 = 0.00f, len2 = 0.00f;

lcd_showstring(30, 130, "touch adjust start", red, white, 16);

while(1){

for(i=0; i<4; i ){ //璇诲彇4涓搴旂殑瑙︽懜灞忓潗鏍?/p>

for(j=0; j<30; j ){ //鐢讳竴涓崄瀛楁灦

lcd_drawpoint(lcd_pos[i][0]-15 j, lcd_pos[i][1], red);

lcd_drawpoint(lcd_pos[i][0], lcd_pos[i][1]-15 j, red);

}

printf("绛夊緟鏍¢獙\r\n");

while(t_pen == 1); //绛夊緟鎸変笅瑙︽懜灞?

delay_ms(50); //寤舵椂50ms寰呮暟鎹ǔ瀹?/p>

printf("鎸変笅瑙︽懜灞廫r\n");

xpt2046_readxyad(&touch_pos[i]);//鑾峰緱瑙︽懜灞忔祴閲忕殑x,y杞存暟鍊?/p>

while(t_pen == 0); //绛夊緟鏉惧紑鎵?/p>

delay_ms(200);

for(j=0; j<30; j ){ //娓呮帀鍗佸瓧鏋跺浘鏍?/p>

lcd_drawpoint(lcd_pos[i][0]-15 j, lcd_pos[i][1], white);

lcd_drawpoint(lcd_pos[i][0], lcd_pos[i][1]-15 j, white);

}

}

//鏍¢獙鍧愭爣-璁$畻鐐瑰嚮鐨勮е鎽哥偣鏄惁姝g‘ 濡傛灉涓嶆纭噸鏂版牎鍑?/p>

//姘村钩涓や釜鐐逛箣闂寸殑璺濈姣旇緝

len1 = (float)sqrt((touch_pos[1].xval-touch_pos[0].xval)*(touch_pos[1].xval-touch_pos[0].xval) \

(touch_pos[1].yval-touch_pos[0].yval)*(touch_pos[1].yval-touch_pos[0].yval));

len2 = (float) sqrt((touch_pos[3].xval-touch_pos[2].xval)*(touch_pos[3].xval-touch_pos[2].xval) \

(touch_pos[3].yval-touch_pos[2].yval)*(touch_pos[3].yval-touch_pos[2].yval));

if(((len1/len2)<0.95) || ((len1/len2)>1.05)){

continue;

}

//鍨傜洿涓や釜鐐逛箣闂寸殑璺濈姣旇緝

len1 = (float)sqrt((touch_pos[2].xval-touch_pos[0].xval)*(touch_pos[2].xval-touch_pos[0].xval) \

(touch_pos[2].yval-touch_pos[0].yval)*(touch_pos[2].yval-touch_pos[0].yval));

len2 = (float)sqrt((touch_pos[3].xval-touch_pos[1].xval)*(touch_pos[3].xval-touch_pos[1].xval) \

(touch_pos[3].yval-touch_pos[1].yval)*(touch_pos[3].yval-touch_pos[1].yval));

if(((len1/len2)<0.95) || ((len1/len2)>1.05)){

continue; //鐐瑰嚮鐨勭偣涓嶇鍚堣姹?/p>

}

//瀵硅绾夸袱涓偣涔嬮棿鐨勮窛绂绘瘮杈?/p>

len1 = (float)sqrt((touch_pos[3].xval-touch_pos[0].xval)*(touch_pos[3].xval-touch_pos[0].xval) \

(touch_pos[3].yval-touch_pos[0].yval)*(touch_pos[3].yval-touch_pos[0].yval));

len2 = (float)sqrt((touch_pos[2].xval-touch_pos[1].xval)*(touch_pos[2].xval-touch_pos[1].xval) \

(touch_pos[2].yval-touch_pos[1].yval)*(touch_pos[2].yval-touch_pos[1].yval));

if(((len1/len2)<0.95) || ((len1/len2)>1.05)){

continue;

}

//璁$畻鏍″噯鍙傛暟 kx (ky)--鏂滅巼锛汢x(by) --鍋忕щ閲?/p>

//璁$畻x鏄犲皠 xlcd = kx * touch_x bx

kx = (float)(lcd_pos[1][0]-lcd_pos[0][0]) / (touch_pos[1].xval-touch_pos[0].xval);

bx = lcd_pos[0][0] - kx*touch_pos[0].xval;

//璁$畻y鏄犲皠 ylcd = ky*touch_y by

ky = (float)(lcd_pos[2][1]-lcd_pos[0][1]) / (touch_pos[2].yval-touch_pos[0].yval);

by = lcd_pos[0][1] - ky*touch_pos[0].yval;

lcd_fill(0, 0, 320, 480, white);

lcd_showstring(30, 130, "touch adjust ok", red, white, 16);

printf("鏍″噯鍙傛暟 ky=%f;kx=%f;by=%d;bx=%d;\r\n",ky, kx, by, bx);

delay_ms(1000);

delay_ms(1000);

lcd_fill(0, 0, 320, 480, white);

break;

}

}

1銆丼op锛屽嵆state of power锛岃〃绀虹殑鏄數姹犵殑鍔熺巼鐘舵€侊紝鐩墠鐢佃姱渚涘簲鍟嗗湪缁欏嚭鐢佃姱鍙傛暟鏃讹紝浼氱粰鍑?s锛?0s锛?0s锛?0s鐨勬寔缁姛鐜囷紱浠?0s鐨勬寔缁姛鐜囦负渚嬩綔涓鸿в閲婏細鐢佃姱鍦?0s鍐呬互涓嶅ぇ浜庤〃鏍间腑缁欏嚭鐨勫姛鐜囨寔缁斁鐢靛彲浠ヤ繚璇佷笉浼氬奖鍝嶇數鑺殑瀵垮懡涓庝娇鐢紱濡傝〃1涓墍绀猴紝涓?淇濊瘉涓嶆硠瀵嗭紝灏哠op鐨勫叿浣撴暟鎹垹闄や簡銆?/p>

琛?锛氭牴鎹俯搴︿笌soc鏌ヨ〃鐨凷op鍊? 2銆佷竴鑸儏鍐典笅锛岃〃鏍间腑缁欏嚭鐨凷op鐨勫€奸兘鏄牴鎹ぇ閲忓疄楠屽疄娴嬩互鍙婃彃鍊煎緱鍑猴紝鑰屼笖鏄浉瀵逛繚瀹堢殑鏁板€硷紱鍙﹀涓€绉嶇浉瀵圭簿纭殑鏂规硶鏄湪绾夸及绠楃數鑺殑鏋佸寲鍐呴樆涓庣洿娴佸唴闃讳互鍙婃瀬鍖栫數瀹圭瓑鍙傛暟锛屼篃灏辨槸涓€鑸鐨勪簩闃禦c妯″瀷锛屽弽鎺ㄥ嚭sop锛堟牴鎹綋鍓嶄及璁$殑鍙傛暟浠ュ強鎴嚦鐢靛帇涓烘潯浠讹紝鍙互绠楀嚭浠庡綋鍓嶇姸鎬佺珛鍗虫斁鐢佃嚦鎴嚦鐢靛帇鎵€闇€鐢垫祦锛屼及绠楀嚭鐨勭數娴佷笌鎴嚦鐢靛帇鐨勪箻绉嵆涓轰笅涓€鏃跺埢鐢佃姱鐨勫疄鏃禨op锛夛紝杩欑鏂规硶鎴戜滑鍚庨潰鍐嶈璁猴紝涓嶈繃娆㈣繋鐣欒█浜ゆ祦鍝︺€?/p>

3銆佹垜浠厛璁ㄨ鍩轰簬鏌ヨ〃鏂瑰紡濡備綍璁$畻鐢佃姱鐨勫疄鏃禨op鍊硷紝涓€鑸儏鍐典笅鎴戜滑浼氬皢鐢佃姱鍘傜粰鍑虹殑5s鎴栬€?0s鐨勬寔缁姛鐜囦綔涓虹數鑺殑宄板€煎姛鐜囷紝鍗砅eakpower锛涘皢30s鎴栬€?0s鐨勬寔缁姛鐜囦綔涓哄父鍊煎姛鐜囷紝鍗矯onstpower銆?/p>

涓轰簡鑳藉鏇村ソ鐞嗚в涓ょ鍔熺巼锛屾垜浠互钃勬按姹犱负渚嬶細姘撮緳澶存斁姘磋繘鍏ヨ搫姘存睜锛岃搫姘存睜搴曢儴鏈夊皬瀛斿彲浠ユ祦鍑烘按锛屽嘲鍊煎姛鐜囧彲浠ョ悊瑙d负姘撮緳澶存祦閲忕獊鐒舵毚娑紝钃勬按姹犱繚鎸佷笉浼氭孩鍑虹殑鑳藉姏锛涘父鍊煎姛鐜囧彲浠ョ悊瑙d负姘撮緳澶存祦閲忕ǔ瀹氭椂锛岃搫姘存睜淇濇寔涓嶄細婧㈠嚭鐨勮兘鍔涳紱寰堟槑鏄撅紝娴侀噺鏆存定涓嶅彲浠ユ槸涓€涓暱鏃堕棿鐨勭姸鎬侊紝鍚﹀垯钃勬按姹犺偗瀹氫細婧㈠嚭銆傛按榫欏ご鐨勬祦閲忎笉鍙兘涓€鐩寸ǔ瀹氾紝閭d箞鎴戜滑姣忎釜鏃跺埢閮介渶瑕佽绠楀嚭涓€涓墍璋撶殑姘撮緳澶寸殑鏈€澶ф祦閲忥紝鍙灏忎簬绛変簬鏈€澶ф祦閲忥紝灏变繚璇佽搫姘存睜涓€鐩翠笉婧㈠嚭銆?/p>

鍥?锛氬舰璞$殑钃勬按姹? 鎴戜滑鐢ㄥ叕寮忚繘琛屼笅涓€姝ラ暱鐨勫疄鏃禨op鐨勬帹瀵艰绠楋紝璁惧嘲鍊兼斁鐢靛姛鐜囦负xp锛?0s锛夛紝甯稿€兼斁鐢靛姛鐜囦负xc锛?0s锛夛紝鏁磋溅鐨勫綋鍓嶅疄闄呮斁鐢靛姛鐜囦负xf锛堜竴寮€濮嬬粰鍒版暣杞︾殑鍙敤鍔熺巼灏辨槸宄板€煎姛鐜囷紝鐒跺悗鏍规嵁鍏紡瀹炴椂璋冩暣锛夛紱

鍥?锛氭埅鑷冲埌t0鏃跺埢璁$畻瀹為檯鍔熺巼瓒呭嚭甯稿€煎姛鐜囩殑绉垎鍊? 鍥?鐢ㄤ簬璁$畻鎴嚦鍒皌0鏃跺埢璁$畻瀹為檯鍔熺巼瓒呭嚭甯稿€煎姛鐜囩殑绉垎鍊紋1锛?/p>

鐢垫睜绠$悊绯荤粺鐨凷op浼扮畻锛堝熀浜庢煡琛ㄦ柟寮忥級 鍥?锛氬嘲鍊煎姛鐜囪秴杩囧父鍊煎姛鐜囩殑绉垎鍊? 鍥?鐢ㄤ簬璁$畻宄板€煎姛鐜囪秴杩囧父鍊煎姛鐜囩殑绉垎鍊紋2锛?/p>

姝ゆ椂鎴戜滑鍙互瀹氫箟涓€涓郴鏁癋actor锛岀敤浜庤〃绀簓1涓巠2鐨勬帴杩戠▼搴︼細

鍥?锛氬姛鐜囩郴鏁扮殑璁$畻 鍏跺疄浠庡浘2鍜屽浘3鍙互鐪嬪嚭锛屽姛鐜囪绠楁槸浠庤兘閲忕殑瑙掑害锛堝姛鐜囧鏃堕棿鐨勭н鍒嗭級杩涜鍒嗘瀽鐨勶紝f鐨勫€艰秺鎺ヨ繎1锛岃鏄庡彲鐢ㄨ兘閲忚秺澶氾紝涔熷氨鏄笅涓€绉掕兘鐢ㄧ殑鍔熺巼瓒婂ぇ锛沠瓒婃帴杩?锛岃鏄庡彲鐢ㄨ兘閲忚秺灏戯紝褰揻=0鏃讹紝涓€鑸鏃跺氨鐩存帴璁や负鐢佃姱鐨勫彲鐢ㄥ姛鐜囧氨鏄父鍊煎姛鐜囦簡锛涚粨鍚坒锛屾垜浠彲浠ヤ互涓嬮潰鐨勫叕寮忎綔涓轰笅涓€绉掑疄鏃跺姛鐜囩殑棰勭畻锛?/p>

鍥?锛氫笅涓€鏃跺埢瀹炴椂鍔熺巼鐨勪及绠楀叕寮? 鎸夌収鍥?鐨勮绠楀叕寮忥紝xnext鑲畾鏄粙浜嶺c涓嶺p涔嬮棿鐨勫€硷紝涓旂鍚堝姛鐜囦娇鐢ㄧ殑鎰熸€ц鐭ワ紝f瓒婂ぇ锛屼笅涓€鏃跺埢鐨勫彲鐢ㄥ姛鐜囩xp瓒婃帴杩戯紱褰撶劧浜嗕篃鍙互閲囧彇鍏朵粬鐨勫叕寮忚繘琛屼及绠楋紱

4銆佷互涓婂氨鏄熀浜庢煡琛ㄧ殑鏂瑰紡锛屽涓嬩竴鏃跺埢鍔熺巼棰勪及鐨勬柟娉曪紝涓嶈繃杩欑鏂瑰紡鐨勫紛绔湪浜庨渶瑕佸湪鐢佃姱鐨勬暣涓敓鍛藉懆鏈熻繘琛屽ぇ閲忚瘯楠岋紝淇濊瘉杞欢鏌ヨ〃鐨勫噯纭€э紱鍙﹀灏辨槸鏃犳硶鏈€澶у寲鐢佃姱鐨勫姛鐜囦娇鐢紝濂藉鍦ㄤ簬鍙互淇濊瘉鐢佃姱鐨勪娇鐢ㄥ鍛斤紱鏂囦腑鎻愬埌鐨勫湪绾垮疄鏃朵及绠楃殑鏂瑰紡鍙互鏈€澶у寲鐢佃姱鐨勫姛鐜囦娇鐢紝浣嗘槸瀵逛簬瀵垮懡浣跨敤鐨勫奖鍝嶈繕鏄緝澶х殑锛屽悇鏈夊埄寮婂惂锛涚洰鍓嶅ぇ閮ㄥ垎浣跨敤鐨勯兘鏄煡琛紝鍥犱负杞欢鍋氳捣鏉ユ瘮杈冪畝鍗曪紝鐩稿鏇村彲闈犱簺锛?/p>

鈥斺€旀潵鑷猆csb涓囬泤濠峰崥澹殑鎶ュ憡

鐩綍

涓€銆佹憳瑕侊細

浜屻€佸紩瑷€锛?/p>

涓夈€佷笁绉嶉泦鎴愭柟妗堬細

鍥涖€佺涓変唬闆嗘垚鏂规鐩存帴鍦ㄧ琛簳涓婇泦鎴愯瑙o細

涓€銆佹憳瑕侊細

鑷粍瑁呴噺瀛愮偣锛圦d锛夊鐩婁粙璐ㄤ笌浼犵粺閲忓瓙闃憋紙qw锛夌粨鏋勫拰鍧椾綋鏉愭枡鐩告瘮锛屽叿鏈夊绉嶄紭鑹殑鏉愭枡鐗规€э紝鍖呮嫭瀵规潗鏂欑己闄风殑鑰愬彈鎬уぇ銆佸弽灏勭伒鏁忓害浣庛€佺嚎瀹藉寮哄洜瀛愬嚑涔庝负闆躲€侀€忔槑鐢垫祦瀵嗗害浣庛€佸伐浣滄俯搴﹂珮锛屽崐瀵间綋閿佹ā婵€鍏夊櫒鍜屾斁澶у櫒鐨勮秴蹇鐩婂姩鍔涘銆傝繖閲岋紝鎴戝皢璁ㄨ閲忓瓙鐐规縺鍏夊櫒棰嗗煙鐨勬渶鏂拌繘灞曪紝閲嶇偣鏄鐨勭洿鎺ョ敓闀裤€傜鍏夊瓙瀛﹀緱鍒颁簡骞挎硾鐨勫簲鐢紝鐗瑰埆鏄湪澶у閲忓簲鐢ㄥ拰涓嶤mos鐢靛瓙瀛︾殑鍗忓悓闆嗘垚鏂归潰銆傛垜灏嗛鍏堟杩拌棰嗗煙锛岀劧鍚庢€荤粨璁惧鎬ц兘鍜屾敼鍠勫搷搴旂殑鍩烘湰鐗╃悊鍩虹銆傛渶鏂拌繘灞曞寘鎷?19掳c杩炵画娉㈡縺鍏夈€佽繎闆剁嚎瀹藉寮哄洜瀛愩€佹棤闅旂鍣ㄧǔ瀹氭€с€?5掳c涓嬭秴杩?00骞寸殑澶栨帹瀵垮懡銆佸井灏哄害鐜舰婵€鍏夎厰涓殑杩炵画娉簹姣畨闃堝€笺€侀珮鐗囦笂澧炵泭锛?9 db锛夋斁澶э紝4.1tb/s浼犺緭锛岄噰鐢ㄤ綆瀹氭椂鎶栧姩锛?2.7fs锛夌殑閿佹ā婵€鍏夊櫒鍜屼晶妯℃姂鍒舵瘮澶т簬45db銆佽皟璋愯寖鍥翠负16nm鐨勫彲璋冭皭婵€鍏夊櫒銆傚湪杩囧幓鐨勫崄骞撮噷锛岄噺瀛愮偣鎶€鏈凡缁忓彇寰椾簡寰堝ぇ鐨勮繘灞曪紝浣垮緱瀹炵敤鐨処ii-v/si鍏夊瓙瀛︽湁鍙兘瀹炵幇鍟嗕笟鍖栥€?/p>

浜屻€佸紩瑷€锛?/p>

鐩墠鍍忚皟鍒跺櫒锛屾帰娴嬪櫒锛岃€﹀悎鍣ㄧ瓑閮藉疄鐜颁簡si涓婄殑闆嗘垚锛屼絾si涓婂厜婧愪竴鐩存槸涓€涓洰鍓嶉潰涓寸殑鎸戞垬锛涘洜涓篠i鍩哄彲浠ヤ笌cmos宸ヨ壓鍏煎锛屽ぇ澶ч檷浣庢垚鏈紝鑰孲i浣滀负鐩存帴甯﹂殭鍗婂浣擄紝鍙戝厜鏁堢巼浣庯紝寰堥毦鎴愪负鍏夋簮鏉愭枡锛岀洰鍓嶅皾璇曚簡si鍩虹殑ge婵€鍏夊櫒锛岄槇鍊肩數娴佸お澶ф槸300ka/cm2锛岃€屼紶缁熺殑涓変簲鏃忛槇鍊肩數娴佺害涓?.1ka/cm2锛屾墍浠ヨ繕鏄皢涓変簲鏃忓拰si娣峰悎闆嗘垚鍚с€?/p>

涓夈€佷笁绉嶉泦鎴愭柟妗堬細

涓€浠f柟妗堬細

澶栭儴鑰﹀悎锛氬嵆鍒╃敤鑰﹀悎鍣ㄥ皢澶栭儴鍏夋簮寮曞叆鍒扮娉㈠涓紱浼樼偣鏄?绠€鍗曞揩閫燂紱缂虹偣鏄?灏佽鎶€鏈鏉傦紝闇€瑕佷娇鐢ㄤ笁浜旀棌琛簳锛屾垚鏈珮锛屽昂瀵稿ぇ锛岄毦浠ュぇ瑙勬ā鐨勫彂灞曪紝灏佽鑰﹀悎鎴愭湰鍗犲埌80-90%銆?/p>

浜屼唬鏂规锛?/p>

娣峰悎闆嗘垚锛氶噰鐢ㄤ笁浜旀棌鍙戝厜鏉愭枡涓庣鍩烘棤婧愭潗鏂欑殑娣峰悎闆嗘垚銆傚埄鐢˙cb绱鑳堕敭鍚堬紝浣庢俯姘у垎瀛愮瓑绂诲瓙閿悎锛屽皢涓変簲鏃忛敭鍚堝埌纭呰‖搴曚笂锛屽噺灏戜簡灏佽鑰﹀悎鐨勬垚鏈紝閫氳繃鍊忛€濇尝鐨勮€﹀悎鏂瑰紡瀹炵幇涓変簲婵€鍏夊櫒鍜岀娉㈠涔嬮棿鐨勮€﹀悎锛屽噺灏戣€﹀悎鎴愭湰銆侷ntel涓昏鐢ㄨ繖涓€濊矾銆偮?聽 聽 聽 聽 聽 聽

聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 鍥?-1聽intel鍏徃娣峰悎闆嗘垚浜у搧

intel杩欎簺鍏夋ā鍧楀浼犵粺鐨勪笁浜旀棌鍗婂浣撳厜妯″潡褰㈡垚浜嗗啿鍑伙紝鍏夋ā鍧楀涓嶅悓鐨勫簲鐢ㄦ潗鏂欎笉鍚岋紝鍍忓厜閫氫俊dfb,bbr閲囩敤鐨勬槸inp,ingaas鏉愭枡锛岃€岀煭璺濋€氫俊vcsel鐢℅aas, algaas鏉愭枡锛屽厜璋冨埗鍣ㄤ娇鐢ㄧ殑閾岄吀閿侺inbo3锛屽厜鐢垫帰娴嬪櫒浣跨敤ingaas鏉愭枡锛屾棤婧愬厜娉㈠閲囩敤鐨勬槸浜屾哀鍖栫锛岀锛屼互鍙婃崯鑰楁洿灏忕殑姘寲纭咃紝姘哀鍖栫锛岄殧绂诲櫒閲囩敤楂樻棆鍏夊害锛屼綆鎹熻€楃殑yig钖勮啘锛屾贩鍚堥泦鎴愬氨鍙互寰堝ソ鐨勫厠鏈嶈繖浜涙潗鏂欎箣闂寸殑鏅舵牸涓嶅尮閰嶏紝瀹炵幇鍚勭鍔熻兘鍦ㄧ涓婂ぇ瑙勬ā鍏夌殑闆嗘垚銆備絾鏄敭鍚堝拰鑰﹀悎鐨勮繃绋嬬殑鑹搧鐜囨槸寰堜綆鐨勶紝宸ヨ壓鍛ㄦ湡寰堥暱锛屾垚鏈洰鍓嶈繕涓嶄綆銆?/p>

涓変唬鏂规

鐩存帴鍦ㄧ琛簳涓婄敓闀夸笁浜旀棌鏉愭枡锛?/p>

聽gaasinpsisoi琛簳浠锋牸锛堢編鍏?骞虫柟鍘樼背锛?.654.550.21.3鏈€澶у昂瀵革紙mm锛?00150450450

聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 琛?-1聽涓嶅悓鏉愭枡鐨勮‖搴曚环鏍煎拰鏈€澶у昂瀵?/p>

鎶€鏈毦搴︽渶澶э紝绂讳骇涓氬寲鏈€杩滐紝浣嗘渶鏈夋晥鐨勬柟寮忥紱闄愬埗鍥犵礌锛?.2%鐨勬櫠鏍煎け閰嶏紙绌块€忎綅閿欙級锛屼笉鍚岀殑鐑啫鑳€绯绘暟锛堝井瑁傜紳锛夛紝涓嶅悓鐨勬瀬鎬э紙鍙嶇浉鐣达級銆?/p>

鍥涖€佺涓変唬闆嗘垚鏂规鐩存帴鍦ㄧ琛簳涓婇泦鎴愯瑙o細

聽 聽 聽 聽 浣嶉敊鍦ㄥ畯瑙備笂琛ㄧ幇涓轰笁浜旀潗鏂欑殑寮€瑁傛柇灞傦紝寰琛ㄧ幇涓烘縺鍏夊櫒鏈夋簮鍖哄紩鍏ュぇ閲忕殑闈炶緪灏勪腑蹇冿紝瀵艰嚧鍙戝厜鏁堢巼浣庯紝鏈熼棿鐨勯槇鍊肩數娴佸鍔狅紝gaas/algaas涓婄殑浣嶉敊瀵嗗害鐩墠闄嶈嚦1e6/cm2锛屼絾鍣ㄤ欢瀵垮懡寰堜綆鍦ㄥ嚑涓皬鏃讹紝鑰岄噺瀛愮偣婵€鍏夊櫒鐨勫鍛藉嵈鍙珮杈?000澶氬皬鏃躲€傞噺瀛愮偣鍏夊鐗规€т负浠€涔堝彈浣嶉敊鐨勫奖鍝嶄綆锛屽彲浠ュ疄鐜伴珮璐ㄩ噺鐨勫彂鍏夊櫒浠?

聽 聽 聽 聽閲忓瓙闃辩殑杞芥祦瀛愭墿鏁i暱搴﹀ぇ姒傚湪10涓井绫筹紝鍦ㄨ繖涓簩缁撮噺瀛愭潗鏂欒杽鑶滃綋涓紝浣嶉敊闈炲父瀹规槗鍦ㄨ杽鑶滃眰閲岃鐢熷拰浼犳挱锛屼粠鑰岄檷浣庡彂鍏夋晥鐜囷紝鑰岄噺瀛愮偣鐨勮浇娴佸瓙鎵╂暎闀垮害鍙湁閲忓瓙闃辩殑鍗佸垎涔嬩竴涓嶅埌锛岃浇娴佸瓙鍦ㄦ潗鏂欎腑鐨勮繍鍔ㄥ彈鍒颁笁缁撮檺鍒讹紝閬囧埌浣嶉敊缂洪櫡骞惰鍏舵崟鑾风殑鍙兘鎬у氨寰堝皬锛岄噺瀛愮偣鐨勫瘑搴﹁杩滃ぇ浜庝綅閿欏瘑搴︼紝鍗充娇鍗曚釜鏈変綅閿欓噺瀛愮偣锛屽苟涓嶄細褰卞搷鍏朵粬閲忓瓙鐐圭殑鍏夊鎬ц兘锛屼粠鑰屽氨澶у箙鍑忓皬浜嗕綅閿欏鍏跺厜瀛︾壒鎬х殑褰卞搷銆?/p>

聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 鍥?-1聽 閲忓瓙闃卞拰閲忓瓙鐐圭殑缁撴瀯鍙婄壒鎬?/p>

聽浠€涔堟槸閲忓瓙鐐瑰憿锛熼噺瀛愮偣锛氱數瀛愬湪涓変釜缁村害涓婇兘鍙楅檺鍒讹紝鏈€浣庝袱涓垎绔嬭兘绾у樊澶т簬鍑犲€嶇殑kt銆備綋鏉愭枡-閲忓瓙闃?閲忓瓙鐐癸細闃堝€肩數娴佸瘑搴︽洿浣庯紝鏇撮珮鐨勫娓╁害渚濊禆涓嶆晱鎰熴€佹洿绐勭殑澧炵泭璋憋紝鐜板湪鍙互閫氳繃鍒嗗瓙鏉熷寤舵妧鏈紝鎶婃潗鏂欑殑鐢熼暱绮惧害鎺у埗鍦ㄥ師瀛愬昂搴︺€?/p>

聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽鍥?-2聽浣撴潗鏂欍€侀噺瀛愰槺銆侀噺瀛愮嚎銆侀噺瀛愮偣缁撴瀯锛堜笉鏄緢鎳備笅闈㈢殑鏇茬嚎浠€涔堟剰鎬濓級

聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽鍥?-3 sk閲忓瓙鐐硅嚜缁勮鐢熼暱妯″紡

鐢熼暱鐨勮繃绋嬫槸棣栧厛灏咺nas娌夌н鍦ㄥ拰瀹冩櫠鏍煎け閰嶆瘮杈冨ぇ鐨勪絾琛ㄩ潰锛堬級涓嶆槸寰堝ぇ鐨勫紓璐ㄧ粨鏉愭枡浣撶郴gaas涓婏紝閭d箞澶栧欢鐢熼暱鐨勫垵鏈熷氨浼氫粠鍑犱釜鍘熷瓙灞傚帤鐨勪簩缁村眰鐘剁敓闀垮紑濮嬶紝骞朵笖闅忕潃灞傚帤鐨勫鍔狅紝搴斿彉鐨勪笉鏂н绱紝杩囨浮鍒颁笁缁村娉㈢敓闀匡紝浠ラ檷浣庣郴缁熺殑鑳介噺锛屼笁缁村鐢熼暱鍒濇湡鎵€褰㈡垚鐨勭撼绫抽噺绾у昂瀵哥殑灏忓鍛ㄥ洿鏄病鏈変綅閿欑殑锛屾帴涓嬫潵鍐嶇敤绂佸甫瀹藉害姣旇緝澶х殑鏉愭枡灏嗗叾鍖呭洿锛屽皬瀵间腑鐨勮浇娴佸瓙灏变細鍙楀埌涓夌淮闄愬埗锛岄偅涔堥噺瀛愮偣灏卞舰鎴愪簡銆傝繖绉嶉噺瀛愮偣鏉愭枡鍏锋湁绫讳技浜庡師瀛愮殑鍛堣剦鍐插嚱鏁颁綋瀵嗗害鍑芥暟锛屾渶浣庝袱涓垎绔嬭兘绾ц兘閲忓樊澶т簬鍑犱釜kt锛屾墍浠ュ氨涓嶄細澧炵泭鍑芥暟鐨勭儹渚濊禆鎴栨槸婵€鍏変緷璧栫殑灞曞銆?/p>

1994骞撮噺瀛愮偣婵€鍏夊櫒棣栨闂笘锛屼絾褰撴椂鐨勯槇鍊肩數娴佸瘑搴︿负7.6ka/cm2锛?7k鑴夊啿妯″紡涓嬪伐浣溿€傞殢鐫€鍦ㄧ敓闀胯繃绋嬩腑锛屼汉浠閲忓瓙鐐圭殑澶у皬銆佸瘑搴︺€佸舰璨屻€佸昂瀵稿潎鍖€鎬с€佷互鍙婂爢鍨涚殑灞傛暟鏇村ソ鐨勬帶鍒讹紝浠呬粎浜斿勾鍚庯紝ucl鍒樻儬浜戣棰樼粍閲忓瓙鐐规縺鍏夊櫒棣栨瓒呰繃閲忓瓙闃憋紙26a/cm2锛岀洰鍓嶆渶浣庣殑闃堝€肩數娴佸瘑搴︿负10a/cm2锛屽彲浠ュ湪楂樻俯220搴︾殑鏉′欢涓嬪伐浣溿€傦級

閲忓瓙鐐瑰湪浣滀负婵€鍏夊櫒鐨勯珮鏁堝彂鍏変腑蹇冪殑鍚屾椂锛屾湁鏁堝噺灏忎綅閿欏瘑搴︾殑褰卞搷锛屽垬鎯犱簯鑰佸笀鏈€鏃╁疄鐜扮琛簳涓婄洿鎺ヤ笂闀縊娉㈡閲忓瓙鐐规縺鍏夊櫒锛屽苟涓旈殢鍚庨娆℃姤閬撲簡鍦ㄥ娓╄繛缁伐浣滄ā寮忎笅瓒呰繃3100灏忔椂鐨勮秴浣庨槇鍊奸噺瀛愮偣婵€鍏夊櫒銆?987骞达紝纭呬笂閲忓瓙闃辨縺鍏夊櫒鍙湁10s鐨勭敓闀垮鍛斤紝纭呭熀閲忓瓙鐐规縺鍏夊櫒寮傚啗绐佽捣銆?/p>

浣嗘槸瑕佸疄鐜颁骇涓氬寲锛岃鍙戝睍鏍囧噯鐨凜mos宸ヨ壓鍏煎鐨勯浂鍋忥紙001锛夌琛簳涓婄洿鎺ョ敓闀夸笁浜旀棌鍗婂浣撴縺鍏夊櫒鐨勬妧鏈€傜洰鍓嶄竾鍗氬+璇鹃缁勪袱绉嶆柟妗堬紝绗竴绉嶆槸涓嬪浘鍙冲浘鎵€绀猴細閫氳繃瓒呮櫠缁撴瀯涓庡井鍨嬭秴鏅舵妧鏈殑缁撳悎杩涗竴姝ュ噺灏忎簡浣嶉敊锛屽痉鍥藉叕鍙歌喘涔扮殑si涓婇暱鐨勫嚑涔庢病鏈変换浣曚綅閿欏瘑搴﹀拰鍙嶇浉鐣寸殑gap澶栧欢鐗囷紝鍐嶅湪涓婇潰杩涜gaas鐨勫寤剁敓闀匡紝tdd鏄寚浣嶉敊瀵嗗害銆傚彟涓€绉嶅垬绾編鑰佸笀鐨勫悎浣滐紝楂樻繁瀹芥瘮娌熸ы闄愬埗鎶€鏈紝闄愬埗鏄厤浣嶉敊涓庡弽鐩哥暣锛屾妸缂洪櫡鎺у埗鍦╒鍨嬫ы閲岋紝涔熷彲浠ュ緢鏈夋晥鐨勬帶鍒朵綅閿欏拰鍙嶇浉鐣淬€?/p>

文章爱游戏平台的版权声明:除非注明,否则均为苗坤旺离型膜原创文章,转载或复制请以超链接形式并注明出处。

发表评论

快捷回复: 表情:
applausebadlaughcoffeefabulousfacepalmfecesfrownheyhainsidiouskeepfightingnoprobpigheadshockedslapsocialsweattolaughwatermelonwittywowyeahyellowdog
评论列表 (暂无评论,2人围观)

还没有评论,来说两句吧...

微信二维码
微信二维码
支付宝二维码
网站地图