当前位置:   article > 正文

Xilinx FPGA:vivado fpga与EEPROM的IIC通信,串口显示数据,含使用debug教程

Xilinx FPGA:vivado fpga与EEPROM的IIC通信,串口显示数据,含使用debug教程

一、实验要求

实现FPGA与EEPROM的通信,要求FPGA对EEPROM实现先“写”后“读”,读出的值给uart发送端并显示到电脑上,按下按键1让fpga对EEPROM写入数据;按下按键2让fpga读出对EEPROM写入过的数据。

二、信号流向图

三、程序设计

(1)按键消抖模块

  1. `timescale 1ns / 1ps
  2. module key(
  3. input sys_clk ,
  4. input rst_n ,
  5. (* MARK_DEBUG="true" *)input key1 ,
  6. (* MARK_DEBUG="true" *)input key2 ,
  7. (* MARK_DEBUG="true" *)output key_flag_1 ,
  8. (* MARK_DEBUG="true" *)output key_flag_2
  9. );
  10. parameter delay = 20'd1_000_000 ; //20ms=20_000_000 20_000_000/20 == 10_000_00
  11. reg[19:0] cnt1 ;
  12. reg[19:0] cnt2 ;
  13. always@(posedge sys_clk )
  14. if(!rst_n)
  15. cnt1 <= 0 ;
  16. else if ( key1 == 0 )begin
  17. if ( cnt1 == delay -1 )
  18. cnt1 <= cnt1 ;
  19. else
  20. cnt1 <= cnt1 +1 ;
  21. end
  22. else
  23. cnt1 <= 0 ;
  24. always@(posedge sys_clk )
  25. if(!rst_n)
  26. cnt2 <= 0 ;
  27. else if ( key2 == 0 )begin
  28. if ( cnt2 == delay -1 )
  29. cnt2 <= cnt2 ;
  30. else
  31. cnt2 <= cnt2 +1 ;
  32. end
  33. else
  34. cnt2 <= 0 ;
  35. assign key_flag_1 = ( cnt1 == delay -2 )?1:0 ;
  36. assign key_flag_2 = ( cnt2 == delay -2 )?1:0 ;
  37. endmodule

(2)数据产生模块

  1. `timescale 1ns / 1ps
  2. module data_generate(
  3. input sys_clk ,
  4. input rst_n ,
  5. input iic_end ,
  6. input key_flag_1 ,
  7. input key_flag_2 ,
  8. (* MARK_DEBUG="true" *)output reg wr_en ,
  9. (* MARK_DEBUG="true" *)output reg rd_en ,
  10. (* MARK_DEBUG="true" *)output reg iic_start //按键消抖后延迟1000个时钟周期
  11. );
  12. always@(posedge sys_clk )
  13. if(!rst_n)
  14. wr_en <= 0 ;
  15. else if ( key_flag_1 )
  16. wr_en <= 1 ;
  17. else if ( iic_end )
  18. wr_en <= 0 ;
  19. else
  20. wr_en <= wr_en ;
  21. always@(posedge sys_clk )
  22. if(!rst_n)
  23. rd_en <= 0 ;
  24. else if ( key_flag_2 )
  25. rd_en <= 1 ;
  26. else if ( iic_end )
  27. rd_en <= 0 ;
  28. else
  29. rd_en <= rd_en ;
  30. ///cnt
  31. parameter TIME_COUNT = 10'd1000 ;
  32. (* MARK_DEBUG="true" *)reg[9:0] cnt ;
  33. always@(posedge sys_clk )
  34. if(!rst_n )
  35. cnt <= 0 ;
  36. else if ( wr_en || rd_en )begin
  37. if ( cnt == TIME_COUNT -1 )
  38. cnt <= cnt ;
  39. else
  40. cnt <= cnt +1 ;
  41. end
  42. else
  43. cnt <= 0 ;
  44. iic_start
  45. always@(posedge sys_clk )
  46. if(!rst_n)
  47. iic_start <= 0 ;
  48. else if ( cnt == TIME_COUNT -2 )
  49. iic_start <= 1 ;
  50. else
  51. iic_start <= 0 ;
  52. endmodule

(3)IIC模块

  1. `timescale 1ns / 1ps
  2. module IIC_2
  3. #(
  4. parameter SYSCLK = 50_000_000 ,
  5. IIC_CLK = 400_000 ,
  6. DEVICE_ID = 7'b1010_000
  7. )
  8. (
  9. input sysclk ,
  10. input rst_n ,
  11. input [7:0] data_in ,
  12. input [7:0] addr ,
  13. input iic_start , 尖峰脉冲
  14. input wr_en , ///按键1按下触发
  15. input rd_en , ///按键2按下触发
  16. (* MARK_DEBUG="true" *)output tx_start ,
  17. (* MARK_DEBUG="true" *)output reg [7:0] rd_data ,
  18. (* MARK_DEBUG="true" *)output reg SCL ,
  19. (* MARK_DEBUG="true" *)inout SDA ,
  20. (* MARK_DEBUG="true" *)output iic_end /尖峰脉冲
  21. );
  22. localparam DELAY = SYSCLK/IIC_CLK ;
  23. //三态门
  24. wire sda_en ; ///SDA先作为输出时候的使能信号线
  25. wire sda_in ; 从机给主机的数据线
  26. reg sda_out ; /主机给从机的数据线
  27. assign SDA = (sda_en == 1) ? sda_out : 1'bz ;
  28. assign sda_in = SDA;
  29. 状态机
  30. localparam IDLE = 4'd0 ,
  31. START1 = 4'd1 ,
  32. SEND_DEVICE_W = 4'd2 ,
  33. ACK1 = 4'd3 ,
  34. SEND_ADDR_W = 4'd4 ,
  35. ACK2 = 4'd5 ,
  36. SEND_DATA_W = 4'd6 ,
  37. ACK3 = 4'd7 ,
  38. STOP = 4'd8 ,
  39. START2 = 4'd9 ,
  40. SEND_DEVICE_R = 4'd10 ,
  41. ACK4 = 4'd11 ,
  42. READ_DATA = 4'd12 ,
  43. NOACK = 4'd13 ;
  44. (* MARK_DEBUG="true" *)reg [3:0] cur_state ;
  45. reg [3:0] next_state ;
  46. (* MARK_DEBUG="true" *)reg [7:0] cnt ;
  47. (* MARK_DEBUG="true" *)reg [2:0] cnt_bit ;
  48. (* MARK_DEBUG="true" *)reg ack_flag ;
  49. assign sda_en = (cur_state == ACK1 || cur_state == ACK2 ||
  50. cur_state == ACK3 || cur_state == ACK4 || cur_state == READ_DATA) ? 0 : 1;
  51. assign tx_start = (cur_state == READ_DATA && cnt_bit == 7 && cnt == DELAY - 1) ? 1 : 0;
  52. assign iic_end = (cur_state == STOP && cnt == DELAY - 1) ? 1 : 0;
  53. /state1
  54. always@(posedge sysclk)
  55. if(!rst_n)
  56. cur_state <= IDLE;
  57. else
  58. cur_state <= next_state;
  59. /state2
  60. always@(*)
  61. case(cur_state)
  62. IDLE : begin
  63. if(iic_start == 1)
  64. next_state = START1;
  65. else
  66. next_state = cur_state;
  67. end
  68. START1 :begin
  69. if(cnt == DELAY - 1)
  70. next_state = SEND_DEVICE_W;
  71. else
  72. next_state = cur_state;
  73. end
  74. SEND_DEVICE_W :begin
  75. if(cnt == DELAY - 1 && cnt_bit == 7)
  76. next_state = ACK1;
  77. else
  78. next_state = cur_state;
  79. end
  80. ACK1 :begin
  81. if(cnt == DELAY - 1 && ack_flag == 0) /应答有效
  82. next_state = SEND_ADDR_W;
  83. else if(cnt == DELAY - 1 && ack_flag == 1) /应答无效
  84. next_state = IDLE;
  85. else
  86. next_state = cur_state;
  87. end
  88. SEND_ADDR_W :begin
  89. if(cnt == DELAY - 1 && cnt_bit == 7)
  90. next_state = ACK2;
  91. else
  92. next_state = cur_state;
  93. end
  94. ACK2 :begin
  95. if(cnt == DELAY - 1 && ack_flag == 0 && wr_en) /应答有效
  96. next_state = SEND_DATA_W;
  97. else if(cnt == DELAY - 1 && ack_flag == 0 && rd_en) /应答有效
  98. next_state = START2;
  99. else if(cnt == DELAY - 1 && ack_flag == 1) /应答无效
  100. next_state = IDLE;
  101. else
  102. next_state = cur_state;
  103. end
  104. SEND_DATA_W :begin
  105. if(cnt == DELAY - 1 && cnt_bit == 7)
  106. next_state = ACK3;
  107. else
  108. next_state = cur_state;
  109. end
  110. ACK3 :begin
  111. if(cnt == DELAY - 1 && ack_flag == 0) /应答有效
  112. next_state = STOP;
  113. else if(cnt == DELAY - 1 && ack_flag == 1) /应答无效
  114. next_state = IDLE;
  115. else
  116. next_state = cur_state;
  117. end
  118. STOP :begin
  119. if(cnt == DELAY - 1)
  120. next_state = IDLE;
  121. else
  122. next_state = cur_state;
  123. end
  124. START2 : begin
  125. if(cnt == DELAY - 1)
  126. next_state = SEND_DEVICE_R;
  127. else
  128. next_state = cur_state;
  129. end
  130. SEND_DEVICE_R :begin
  131. if(cnt == DELAY - 1 && cnt_bit == 7)
  132. next_state = ACK4;
  133. else
  134. next_state = cur_state;
  135. end
  136. ACK4 :begin
  137. if(cnt == DELAY - 1 && ack_flag == 0) /应答有效
  138. next_state = READ_DATA;
  139. else if(cnt == DELAY - 1 && ack_flag == 1) /应答无效
  140. next_state = IDLE;
  141. else
  142. next_state = cur_state;
  143. end
  144. READ_DATA :begin
  145. if(cnt == DELAY - 1 && cnt_bit == 7)
  146. next_state = NOACK;
  147. else
  148. next_state = cur_state;
  149. end
  150. NOACK :begin
  151. if(cnt == DELAY - 1)
  152. next_state = STOP;
  153. else
  154. next_state = cur_state;
  155. end
  156. default:next_state = IDLE;
  157. endcase
  158. state3
  159. always@(posedge sysclk)
  160. if(!rst_n)begin
  161. cnt <= 0;
  162. cnt_bit <= 0;
  163. sda_out <= 1; 空闲为1
  164. SCL <= 1;空闲为1
  165. ack_flag <= 1; 无效应答
  166. rd_data <= 0;
  167. end
  168. else
  169. case(cur_state)
  170. IDLE :begin
  171. rd_data <= 0;
  172. cnt <= 0;
  173. cnt_bit <= 0;
  174. sda_out <= 1;
  175. SCL <= 1;
  176. ack_flag <= 1;
  177. end
  178. START1 :begin
  179. ack_flag <= 1;
  180. if(cnt >= DELAY*3/4 - 1)
  181. SCL <= 0;
  182. else
  183. SCL <= 1;
  184. if(cnt >= DELAY/2 - 1)
  185. sda_out <= 0;
  186. else
  187. sda_out <= 1;
  188. cnt_bit <= 0;
  189. if(cnt == DELAY - 1)
  190. cnt <= 0;
  191. else
  192. cnt <= cnt + 1;
  193. end
  194. SEND_DEVICE_W :begin 先发最高位 0-7 0-6 7
  195. ack_flag <= 1;
  196. if(cnt >= DELAY/4 - 1 && cnt <= DELAY*3/4 - 1)
  197. SCL <= 1;
  198. else
  199. SCL <= 0;
  200. if(cnt_bit >=0 && cnt_bit < 7)
  201. sda_out <= DEVICE_ID[6-cnt_bit];
  202. else /cnt_bit == 7
  203. sda_out <= 0; //写标志位
  204. if(cnt == DELAY - 1)
  205. cnt <= 0;
  206. else
  207. cnt <= cnt + 1;
  208. if(cnt == DELAY - 1)
  209. cnt_bit <= cnt_bit + 1;
  210. else
  211. cnt_bit <= cnt_bit;
  212. end
  213. ACK1 :begin /从机给主机数据
  214. if(cnt == DELAY/2 - 1)
  215. ack_flag <= sda_in ;
  216. else
  217. ack_flag <= ack_flag;
  218. if(cnt >= DELAY/4 - 1 && cnt <= DELAY*3/4 - 1)
  219. SCL <= 1;
  220. else
  221. SCL <= 0;
  222. sda_out <= 1;
  223. cnt_bit <= 0;
  224. if(cnt == DELAY - 1)
  225. cnt <= 0;
  226. else
  227. cnt <= cnt + 1;
  228. end
  229. SEND_ADDR_W :begin
  230. ack_flag <= 1;
  231. if(cnt >= DELAY/4 - 1 && cnt <= DELAY*3/4 - 1)
  232. SCL <= 1;
  233. else
  234. SCL <= 0;
  235. sda_out <= addr[7-cnt_bit];
  236. if(cnt == DELAY - 1)
  237. cnt <= 0;
  238. else
  239. cnt <= cnt + 1;
  240. if(cnt == DELAY - 1)
  241. cnt_bit <= cnt_bit + 1;
  242. else
  243. cnt_bit <= cnt_bit;
  244. end
  245. ACK2 :begin
  246. if(cnt == DELAY/2 - 1)
  247. ack_flag <= sda_in ;
  248. else
  249. ack_flag <= ack_flag;
  250. if(cnt >= DELAY/4 - 1 && cnt <= DELAY*3/4 - 1)
  251. SCL <= 1;
  252. else
  253. SCL <= 0;
  254. sda_out <= 1;
  255. cnt_bit <= 0;
  256. if(cnt == DELAY - 1)
  257. cnt <= 0;
  258. else
  259. cnt <= cnt + 1;
  260. end
  261. SEND_DATA_W :begin
  262. ack_flag <= 1;
  263. if(cnt >= DELAY/4 - 1 && cnt <= DELAY*3/4 - 1)
  264. SCL <= 1;
  265. else
  266. SCL <= 0;
  267. sda_out <= data_in[7-cnt_bit];
  268. if(cnt == DELAY - 1)
  269. cnt <= 0;
  270. else
  271. cnt <= cnt + 1;
  272. if(cnt == DELAY - 1)
  273. cnt_bit <= cnt_bit + 1;
  274. else
  275. cnt_bit <= cnt_bit;
  276. end
  277. ACK3 :begin
  278. if(cnt == DELAY/2 - 1)
  279. ack_flag <= sda_in ;
  280. else
  281. ack_flag <= ack_flag;
  282. if(cnt >= DELAY/4 - 1 && cnt <= DELAY*3/4 - 1)
  283. SCL <= 1;
  284. else
  285. SCL <= 0;
  286. sda_out <= 1;
  287. cnt_bit <= 0;
  288. if(cnt == DELAY - 1)
  289. cnt <= 0;
  290. else
  291. cnt <= cnt + 1;
  292. end
  293. STOP :begin
  294. ack_flag <= 1;
  295. if(cnt >= DELAY/4 - 1)
  296. SCL <= 1;
  297. else
  298. SCL <= 0;
  299. if(cnt >= DELAY/2 - 1)
  300. sda_out <= 1;
  301. else
  302. sda_out <= 0;
  303. cnt_bit <= 0;
  304. if(cnt == DELAY - 1)
  305. cnt <= 0;
  306. else
  307. cnt <= cnt + 1;
  308. end
  309. START2 :begin
  310. ack_flag <= 1;
  311. if(cnt >= DELAY*3/4 - 1)
  312. SCL <= 0;
  313. else
  314. SCL <= 1;
  315. if(cnt >= DELAY/2 - 1)
  316. sda_out <= 0;
  317. else
  318. sda_out <= 1;
  319. cnt_bit <= 0;
  320. if(cnt == DELAY - 1)
  321. cnt <= 0;
  322. else
  323. cnt <= cnt + 1;
  324. end
  325. SEND_DEVICE_R :begin
  326. ack_flag <= 1;
  327. if(cnt >= DELAY/4 - 1 && cnt <= DELAY*3/4 - 1)
  328. SCL <= 1;
  329. else
  330. SCL <= 0;
  331. if(cnt_bit >=0 && cnt_bit < 7)
  332. sda_out <= DEVICE_ID[6-cnt_bit];
  333. else /cnt_bit == 7
  334. sda_out <= 1; //读标志位
  335. if(cnt == DELAY - 1)
  336. cnt <= 0;
  337. else
  338. cnt <= cnt + 1;
  339. if(cnt == DELAY - 1)
  340. cnt_bit <= cnt_bit + 1;
  341. else
  342. cnt_bit <= cnt_bit;
  343. end
  344. ACK4 :begin
  345. if(cnt == DELAY/2 - 1)
  346. ack_flag <= sda_in ;
  347. else
  348. ack_flag <= ack_flag;
  349. if(cnt >= DELAY/4 - 1 && cnt <= DELAY*3/4 - 1)
  350. SCL <= 1;
  351. else
  352. SCL <= 0;
  353. sda_out <= 1;
  354. cnt_bit <= 0;
  355. if(cnt == DELAY - 1)
  356. cnt <= 0;
  357. else
  358. cnt <= cnt + 1;
  359. end
  360. READ_DATA :begin
  361. if(cnt == DELAY/2 - 1)
  362. // rd_data[7-cnt_bit] <= sda_in; /法1
  363. rd_data <= {rd_data[6:0],sda_in}; 法2
  364. else
  365. rd_data <= rd_data;
  366. ack_flag <= 1;
  367. if(cnt >= DELAY/4 - 1 && cnt <= DELAY*3/4 - 1)
  368. SCL <= 1;
  369. else
  370. SCL <= 0;
  371. sda_out <= 1;
  372. if(cnt == DELAY - 1)
  373. cnt <= 0;
  374. else
  375. cnt <= cnt + 1;
  376. if(cnt == DELAY - 1)
  377. cnt_bit <= cnt_bit + 1;
  378. else
  379. cnt_bit <= cnt_bit;
  380. end
  381. NOACK :begin
  382. ack_flag <= 1;
  383. if(cnt >= DELAY/4 - 1 && cnt <= DELAY*3/4 - 1)
  384. SCL <= 1;
  385. else
  386. SCL <= 0;
  387. sda_out <= 1;
  388. cnt_bit <= 0;
  389. if(cnt == DELAY - 1)
  390. cnt <= 0;
  391. else
  392. cnt <= cnt + 1;
  393. end
  394. endcase
  395. endmodule

(4)发送端模块

  1. `timescale 1ns / 1ps
  2. module uart_tx(
  3. input sys_clk ,
  4. input rst_n ,
  5. input tx_start ,
  6. (* MARK_DEBUG="true" *) input [7:0] rd_data ,
  7. (* MARK_DEBUG="true" *)output reg tx_data ,
  8. output reg tx_done
  9. );
  10. parameter SYSCLK = 50_000_000 ;
  11. parameter Baud = 115200 ;
  12. parameter COUNT = SYSCLK/Baud;
  13. parameter MID = COUNT/2 ;
  14. //start_flag
  15. reg tx_reg1 ;
  16. reg tx_reg2 ;
  17. (* MARK_DEBUG="true" *)wire start_flag ;
  18. always@(posedge sys_clk )
  19. if(!rst_n)begin
  20. tx_reg1 <= 0 ;
  21. tx_reg2 <= 0 ;
  22. end
  23. else
  24. begin
  25. tx_reg1 <= tx_start ;
  26. tx_reg2 <= tx_reg1 ;
  27. end
  28. assign start_flag = tx_reg1 & ~tx_reg2 ;
  29. //tx_flag
  30. (* MARK_DEBUG="true" *) reg tx_flag ;
  31. (* MARK_DEBUG="true" *) reg [9:0] cnt ;
  32. (* MARK_DEBUG="true" *) reg [4:0] cnt_bit ; //0 12345678 9 10
  33. always@(posedge sys_clk )
  34. if(!rst_n)
  35. tx_flag <= 0 ;
  36. else if ( start_flag )
  37. tx_flag <= 1 ;
  38. else if ( cnt == COUNT -1 && cnt_bit == 10 )
  39. tx_flag <= 0 ;
  40. else
  41. tx_flag <= tx_flag ;
  42. //cnt
  43. always@(posedge sys_clk )
  44. if(!rst_n)
  45. cnt <= 0 ;
  46. else if ( tx_flag )begin
  47. if ( cnt == COUNT -1 )
  48. cnt <= 0 ;
  49. else
  50. cnt <= cnt +1 ;
  51. end
  52. else
  53. cnt <= 0 ;
  54. //cnt_bit
  55. always@(posedge sys_clk )
  56. if(!rst_n)
  57. cnt_bit <= 0 ;
  58. else if ( tx_flag )begin
  59. if ( cnt == COUNT -1 )begin
  60. if ( cnt_bit == 10 )
  61. cnt_bit <= 0 ;
  62. else
  63. cnt_bit <= cnt_bit +1 ;
  64. end
  65. else
  66. cnt_bit <= cnt_bit ;
  67. end
  68. else
  69. cnt_bit <= 0 ;
  70. //寄存rd_data rd_data随着cur_state变为STOP后清零,在uart_tx模块
  71. //中,cnt_bit == 0 的时候可以捕捉到数据
  72. (* MARK_DEBUG="true" *) reg[7:0] data_reg ;
  73. always@(posedge sys_clk )
  74. if(!rst_n)
  75. data_reg <= 0 ;
  76. else if ( tx_flag )begin
  77. if ( cnt_bit == 0 && cnt == MID -1 )
  78. data_reg <= rd_data ;
  79. else
  80. data_reg <= data_reg ;
  81. end
  82. else
  83. data_reg <= data_reg ;
  84. //tx_data
  85. parameter MODE_CHECK = 0 ;
  86. always@(posedge sys_clk )
  87. if(!rst_n) //cnt_bit: 0 12345678 9 10
  88. tx_data <= 0 ; //rd_data: 01234567
  89. else if ( tx_flag )begin
  90. if ( cnt_bit > 0 && cnt_bit <9 )
  91. tx_data <= data_reg [ cnt_bit -1 ] ;
  92. else if ( cnt_bit == 0 )
  93. tx_data <= 0 ;
  94. else if ( cnt_bit == 10 )
  95. tx_data <= 1 ;
  96. else if ( cnt_bit == 9 )
  97. tx_data <= (MODE_CHECK == 0 )? ^rd_data : ~^rd_data ;
  98. else
  99. tx_data <= tx_data ;
  100. end
  101. else
  102. tx_data <= 1 ;
  103. //tx_done
  104. always@(posedge sys_clk )
  105. if(!rst_n)
  106. tx_done <= 0 ;
  107. else if ( tx_flag )begin
  108. if ( cnt == COUNT -1 && cnt_bit == 10 )
  109. tx_done <= 1 ;
  110. else
  111. tx_done <= 0 ;
  112. end
  113. else
  114. tx_done <= 0 ;
  115. endmodule

(5)TOP模块

  1. `timescale 1ns / 1ps
  2. module IIC_TOP(
  3. input sys_clk ,
  4. input rst_n ,
  5. input key1 ,
  6. input key2 ,
  7. output tx_data ,
  8. output SCL ,
  9. inout SDA
  10. );
  11. key
  12. wire key_flag_1 ;
  13. wire key_flag_2 ;
  14. key key_u1(
  15. . sys_clk (sys_clk ) ,
  16. . rst_n (rst_n ) ,
  17. . key1 (key1 ) ,
  18. . key2 (key2 ) ,
  19. . key_flag_1 (key_flag_1 ) ,
  20. . key_flag_2 (key_flag_2 )
  21. );
  22. ///data_generate
  23. wire iic_end ;
  24. wire wr_en ;
  25. wire rd_en ;
  26. wire iic_start ;
  27. data_generate data_generate_u1(
  28. . sys_clk (sys_clk ) ,
  29. . rst_n (rst_n ) ,
  30. . iic_end (iic_end ) ,
  31. . key_flag_1 (key_flag_1) ,
  32. . key_flag_2 (key_flag_2) ,
  33. . wr_en (wr_en ) ,
  34. . rd_en (rd_en ) ,
  35. . iic_start (iic_start ) //按键消抖后延迟1000个时钟周期
  36. );
  37. IIC
  38. wire tx_start ;
  39. wire [7:0] rd_data ;
  40. IIC_2
  41. #(
  42. . SYSCLK (50_000_000 ) ,
  43. . IIC_CLK (400_000 ) ,
  44. . DEVICE_ID (7'b1010_000)
  45. )
  46. IIC_2_u1(
  47. . sysclk (sys_clk) ,
  48. . rst_n (rst_n ) ,
  49. . data_in (8'h45) ,
  50. . addr (8'h12) ,
  51. . iic_start (iic_start) , 尖峰脉冲
  52. . wr_en (wr_en ) , ///按键1按下触发
  53. . rd_en (rd_en ) , ///按键2按下触发
  54. . tx_start (tx_start) ,
  55. . rd_data (rd_data ) ,
  56. . SCL (SCL ) ,
  57. . SDA (SDA ) ,
  58. . iic_end (iic_end ) /尖峰脉冲
  59. );
  60. ///uart_tx
  61. wire tx_done ;
  62. uart_tx uart_tx_u1(
  63. . sys_clk (sys_clk ) ,
  64. . rst_n (rst_n ) ,
  65. . tx_start (tx_start) ,
  66. . rd_data (rd_data ) ,
  67. . tx_data (tx_data ) ,
  68. . tx_done (tx_done )
  69. );
  70. endmodule

(6)绑定管脚

  1. set_property IOSTANDARD LVCMOS33 [get_ports key1]
  2. set_property IOSTANDARD LVCMOS33 [get_ports key2]
  3. set_property IOSTANDARD LVCMOS33 [get_ports rst_n]
  4. set_property IOSTANDARD LVCMOS33 [get_ports SCL]
  5. set_property IOSTANDARD LVCMOS33 [get_ports SDA]
  6. set_property IOSTANDARD LVCMOS33 [get_ports sys_clk]
  7. set_property IOSTANDARD LVCMOS33 [get_ports tx_data]
  8. set_property PACKAGE_PIN M19 [get_ports key1]
  9. set_property PACKAGE_PIN M20 [get_ports key2]
  10. set_property PACKAGE_PIN P15 [get_ports rst_n]
  11. set_property PACKAGE_PIN F19 [get_ports SCL]
  12. set_property PACKAGE_PIN F20 [get_ports SDA]
  13. set_property PACKAGE_PIN K17 [get_ports sys_clk]
  14. set_property PACKAGE_PIN U18 [get_ports tx_data]

四、set up debug使用步骤

然后点set up debug

XDC文件变成这样就是保存成功了

  1. set_property IOSTANDARD LVCMOS33 [get_ports key1]
  2. set_property IOSTANDARD LVCMOS33 [get_ports key2]
  3. set_property IOSTANDARD LVCMOS33 [get_ports rst_n]
  4. set_property IOSTANDARD LVCMOS33 [get_ports SCL]
  5. set_property IOSTANDARD LVCMOS33 [get_ports SDA]
  6. set_property IOSTANDARD LVCMOS33 [get_ports sys_clk]
  7. set_property IOSTANDARD LVCMOS33 [get_ports tx_data]
  8. set_property PACKAGE_PIN M19 [get_ports key1]
  9. set_property PACKAGE_PIN M20 [get_ports key2]
  10. set_property PACKAGE_PIN P15 [get_ports rst_n]
  11. set_property PACKAGE_PIN F19 [get_ports SCL]
  12. set_property PACKAGE_PIN F20 [get_ports SDA]
  13. set_property PACKAGE_PIN K17 [get_ports sys_clk]
  14. set_property PACKAGE_PIN U18 [get_ports tx_data]
  15. create_debug_core u_ila_0 ila
  16. set_property ALL_PROBE_SAME_MU true [get_debug_cores u_ila_0]
  17. set_property ALL_PROBE_SAME_MU_CNT 1 [get_debug_cores u_ila_0]
  18. set_property C_ADV_TRIGGER false [get_debug_cores u_ila_0]
  19. set_property C_DATA_DEPTH 4096 [get_debug_cores u_ila_0]
  20. set_property C_EN_STRG_QUAL false [get_debug_cores u_ila_0]
  21. set_property C_INPUT_PIPE_STAGES 0 [get_debug_cores u_ila_0]
  22. set_property C_TRIGIN_EN false [get_debug_cores u_ila_0]
  23. set_property C_TRIGOUT_EN false [get_debug_cores u_ila_0]
  24. set_property port_width 1 [get_debug_ports u_ila_0/clk]
  25. connect_debug_port u_ila_0/clk [get_nets [list sys_clk_IBUF_BUFG]]
  26. set_property PROBE_TYPE DATA_AND_TRIGGER [get_debug_ports u_ila_0/probe0]
  27. set_property port_width 8 [get_debug_ports u_ila_0/probe0]
  28. connect_debug_port u_ila_0/probe0 [get_nets [list {IIC_2_u1/cnt[0]} {IIC_2_u1/cnt[1]} {IIC_2_u1/cnt[2]} {IIC_2_u1/cnt[3]} {IIC_2_u1/cnt[4]} {IIC_2_u1/cnt[5]} {IIC_2_u1/cnt[6]} {IIC_2_u1/cnt[7]}]]
  29. create_debug_port u_ila_0 probe
  30. set_property PROBE_TYPE DATA_AND_TRIGGER [get_debug_ports u_ila_0/probe1]
  31. set_property port_width 3 [get_debug_ports u_ila_0/probe1]
  32. connect_debug_port u_ila_0/probe1 [get_nets [list {IIC_2_u1/cnt_bit[0]} {IIC_2_u1/cnt_bit[1]} {IIC_2_u1/cnt_bit[2]}]]
  33. create_debug_port u_ila_0 probe
  34. set_property PROBE_TYPE DATA_AND_TRIGGER [get_debug_ports u_ila_0/probe2]
  35. set_property port_width 4 [get_debug_ports u_ila_0/probe2]
  36. connect_debug_port u_ila_0/probe2 [get_nets [list {IIC_2_u1/cur_state[0]} {IIC_2_u1/cur_state[1]} {IIC_2_u1/cur_state[2]} {IIC_2_u1/cur_state[3]}]]
  37. create_debug_port u_ila_0 probe
  38. set_property PROBE_TYPE DATA_AND_TRIGGER [get_debug_ports u_ila_0/probe3]
  39. set_property port_width 10 [get_debug_ports u_ila_0/probe3]
  40. connect_debug_port u_ila_0/probe3 [get_nets [list {data_generate_u1/cnt[0]} {data_generate_u1/cnt[1]} {data_generate_u1/cnt[2]} {data_generate_u1/cnt[3]} {data_generate_u1/cnt[4]} {data_generate_u1/cnt[5]} {data_generate_u1/cnt[6]} {data_generate_u1/cnt[7]} {data_generate_u1/cnt[8]} {data_generate_u1/cnt[9]}]]
  41. create_debug_port u_ila_0 probe
  42. set_property PROBE_TYPE DATA_AND_TRIGGER [get_debug_ports u_ila_0/probe4]
  43. set_property port_width 8 [get_debug_ports u_ila_0/probe4]
  44. connect_debug_port u_ila_0/probe4 [get_nets [list {uart_tx_u1/rd_data[0]} {uart_tx_u1/rd_data[1]} {uart_tx_u1/rd_data[2]} {uart_tx_u1/rd_data[3]} {uart_tx_u1/rd_data[4]} {uart_tx_u1/rd_data[5]} {uart_tx_u1/rd_data[6]} {uart_tx_u1/rd_data[7]}]]
  45. create_debug_port u_ila_0 probe
  46. set_property PROBE_TYPE DATA_AND_TRIGGER [get_debug_ports u_ila_0/probe5]
  47. set_property port_width 8 [get_debug_ports u_ila_0/probe5]
  48. connect_debug_port u_ila_0/probe5 [get_nets [list {IIC_2_u1/rd_data[0]} {IIC_2_u1/rd_data[1]} {IIC_2_u1/rd_data[2]} {IIC_2_u1/rd_data[3]} {IIC_2_u1/rd_data[4]} {IIC_2_u1/rd_data[5]} {IIC_2_u1/rd_data[6]} {IIC_2_u1/rd_data[7]}]]
  49. create_debug_port u_ila_0 probe
  50. set_property PROBE_TYPE DATA_AND_TRIGGER [get_debug_ports u_ila_0/probe6]
  51. set_property port_width 1 [get_debug_ports u_ila_0/probe6]
  52. connect_debug_port u_ila_0/probe6 [get_nets [list IIC_2_u1/ack_flag]]
  53. create_debug_port u_ila_0 probe
  54. set_property PROBE_TYPE DATA_AND_TRIGGER [get_debug_ports u_ila_0/probe7]
  55. set_property port_width 1 [get_debug_ports u_ila_0/probe7]
  56. connect_debug_port u_ila_0/probe7 [get_nets [list IIC_2_u1/iic_end]]
  57. create_debug_port u_ila_0 probe
  58. set_property PROBE_TYPE DATA_AND_TRIGGER [get_debug_ports u_ila_0/probe8]
  59. set_property port_width 1 [get_debug_ports u_ila_0/probe8]
  60. connect_debug_port u_ila_0/probe8 [get_nets [list data_generate_u1/iic_start]]
  61. create_debug_port u_ila_0 probe
  62. set_property PROBE_TYPE DATA_AND_TRIGGER [get_debug_ports u_ila_0/probe9]
  63. set_property port_width 1 [get_debug_ports u_ila_0/probe9]
  64. connect_debug_port u_ila_0/probe9 [get_nets [list key_u1/key1]]
  65. create_debug_port u_ila_0 probe
  66. set_property PROBE_TYPE DATA_AND_TRIGGER [get_debug_ports u_ila_0/probe10]
  67. set_property port_width 1 [get_debug_ports u_ila_0/probe10]
  68. connect_debug_port u_ila_0/probe10 [get_nets [list key_u1/key2]]
  69. create_debug_port u_ila_0 probe
  70. set_property PROBE_TYPE DATA_AND_TRIGGER [get_debug_ports u_ila_0/probe11]
  71. set_property port_width 1 [get_debug_ports u_ila_0/probe11]
  72. connect_debug_port u_ila_0/probe11 [get_nets [list key_u1/key_flag_1]]
  73. create_debug_port u_ila_0 probe
  74. set_property PROBE_TYPE DATA_AND_TRIGGER [get_debug_ports u_ila_0/probe12]
  75. set_property port_width 1 [get_debug_ports u_ila_0/probe12]
  76. connect_debug_port u_ila_0/probe12 [get_nets [list key_u1/key_flag_2]]
  77. create_debug_port u_ila_0 probe
  78. set_property PROBE_TYPE DATA_AND_TRIGGER [get_debug_ports u_ila_0/probe13]
  79. set_property port_width 1 [get_debug_ports u_ila_0/probe13]
  80. connect_debug_port u_ila_0/probe13 [get_nets [list data_generate_u1/rd_en]]
  81. create_debug_port u_ila_0 probe
  82. set_property PROBE_TYPE DATA_AND_TRIGGER [get_debug_ports u_ila_0/probe14]
  83. set_property port_width 1 [get_debug_ports u_ila_0/probe14]
  84. connect_debug_port u_ila_0/probe14 [get_nets [list IIC_2_u1/SCL]]
  85. create_debug_port u_ila_0 probe
  86. set_property PROBE_TYPE DATA_AND_TRIGGER [get_debug_ports u_ila_0/probe15]
  87. set_property port_width 1 [get_debug_ports u_ila_0/probe15]
  88. connect_debug_port u_ila_0/probe15 [get_nets [list IIC_2_u1/SDA_IBUF]]
  89. create_debug_port u_ila_0 probe
  90. set_property PROBE_TYPE DATA_AND_TRIGGER [get_debug_ports u_ila_0/probe16]
  91. set_property port_width 1 [get_debug_ports u_ila_0/probe16]
  92. connect_debug_port u_ila_0/probe16 [get_nets [list IIC_2_u1/SDA_OBUF]]
  93. create_debug_port u_ila_0 probe
  94. set_property PROBE_TYPE DATA_AND_TRIGGER [get_debug_ports u_ila_0/probe17]
  95. set_property port_width 1 [get_debug_ports u_ila_0/probe17]
  96. connect_debug_port u_ila_0/probe17 [get_nets [list uart_tx_u1/tx_data]]
  97. create_debug_port u_ila_0 probe
  98. set_property PROBE_TYPE DATA_AND_TRIGGER [get_debug_ports u_ila_0/probe18]
  99. set_property port_width 1 [get_debug_ports u_ila_0/probe18]
  100. connect_debug_port u_ila_0/probe18 [get_nets [list IIC_2_u1/tx_start]]
  101. create_debug_port u_ila_0 probe
  102. set_property PROBE_TYPE DATA_AND_TRIGGER [get_debug_ports u_ila_0/probe19]
  103. set_property port_width 1 [get_debug_ports u_ila_0/probe19]
  104. connect_debug_port u_ila_0/probe19 [get_nets [list data_generate_u1/wr_en]]
  105. set_property C_CLK_INPUT_FREQ_HZ 300000000 [get_debug_cores dbg_hub]
  106. set_property C_ENABLE_CLK_DIVIDER false [get_debug_cores dbg_hub]
  107. set_property C_USER_SCAN_CHAIN 1 [get_debug_cores dbg_hub]
  108. connect_debug_port dbg_hub/clk [get_nets sys_clk_IBUF_BUFG]

"4"对应后面几个cnt_bit

五、实验结果

按下控制“写”的按键,再按下“读”的按键后,pc端返回45

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号