Publishing for sharing with Harald

Dependencies:   csi059

Committer:
CactusSemi
Date:
Fri May 22 19:19:45 2020 +0000
Revision:
4:1c48c9fa44fc
Parent:
3:3e8c16b6620c
Publishing for sharing with Harald

Who changed what in which revision?

UserRevisionLine numberNew contents of line
CactusSemi 3:3e8c16b6620c 1 #include "mbed.h"
CactusSemi 3:3e8c16b6620c 2
CactusSemi 3:3e8c16b6620c 3 extern Serial pc;
CactusSemi 3:3e8c16b6620c 4 extern int frequ; //unit kHz
CactusSemi 3:3e8c16b6620c 5 extern char dev_addr; //fixed
CactusSemi 3:3e8c16b6620c 6
CactusSemi 3:3e8c16b6620c 7 char get_half_byte(int *); //defined in I2C_read.cpp
CactusSemi 3:3e8c16b6620c 8
CactusSemi 3:3e8c16b6620c 9
CactusSemi 3:3e8c16b6620c 10 char get_byte(int *flag) {
CactusSemi 3:3e8c16b6620c 11 char cur_char;
CactusSemi 3:3e8c16b6620c 12 char temp;
CactusSemi 3:3e8c16b6620c 13 int flag1 = 0;
CactusSemi 3:3e8c16b6620c 14 cur_char = get_half_byte(&flag1);
CactusSemi 3:3e8c16b6620c 15 if (flag1 == 1) {
CactusSemi 3:3e8c16b6620c 16 cur_char = cur_char << 4;
CactusSemi 3:3e8c16b6620c 17 temp = get_half_byte(&flag1);
CactusSemi 3:3e8c16b6620c 18 cur_char = (cur_char | temp);
CactusSemi 3:3e8c16b6620c 19 }
CactusSemi 3:3e8c16b6620c 20 *flag = flag1;
CactusSemi 3:3e8c16b6620c 21 return cur_char;
CactusSemi 3:3e8c16b6620c 22 }
CactusSemi 3:3e8c16b6620c 23
CactusSemi 3:3e8c16b6620c 24 void print_nvm_reg(uint8_t *max_Vout, uint8_t *max_Vout_trim, uint8_t *high_time, uint8_t *low_time, uint8_t *adc_samp_rate,
CactusSemi 3:3e8c16b6620c 25 uint8_t *adc_range, uint8_t *adc_time_out, uint8_t *comp_offset, uint8_t *range_trim, uint8_t *PMOS_off, uint8_t *Driver2, uint8_t *Driver3,
CactusSemi 4:1c48c9fa44fc 26 uint8_t *neg_hlf_rng, uint8_t *CCM_threshold, uint8_t *DMOS_ctrl_trim, uint8_t *adc_op_mode) {
CactusSemi 3:3e8c16b6620c 27
CactusSemi 3:3e8c16b6620c 28 pc.printf("\033[%dm ", 35);//change text color to red
CactusSemi 3:3e8c16b6620c 29 pc.printf("\n\n\n\r\t Register contents :\n\r\t ");
CactusSemi 3:3e8c16b6620c 30 for ( int i = 0; i<26; i++) pc.printf("\304");
CactusSemi 4:1c48c9fa44fc 31 if (*PMOS_off == 0x0f) // ACP Mode
CactusSemi 4:1c48c9fa44fc 32 {
CactusSemi 4:1c48c9fa44fc 33 pc.printf("\n\n\r\t\t ACP Mode \n\n");
CactusSemi 4:1c48c9fa44fc 34 pc.printf("\n\n\r\t 1. max_Vout = 0x%2.2X",*max_Vout);
CactusSemi 4:1c48c9fa44fc 35 pc.printf("\n\n\r\t 2. max_Vout_trim = 0x%2.2X",*max_Vout_trim);
CactusSemi 4:1c48c9fa44fc 36 pc.printf("\n\n\r\t 3. high_time = 0x%2.2X",*high_time);
CactusSemi 4:1c48c9fa44fc 37 pc.printf("\n\n\r\t 4. low_time = 0x%2.2X",*low_time);
CactusSemi 4:1c48c9fa44fc 38 pc.printf("\n\n\r\t 5. adc_samp_rate = 0x%2.2X",*adc_samp_rate);
CactusSemi 4:1c48c9fa44fc 39 pc.printf("\n\n\r\t 6. adc_range = 0x%2.2X",*adc_range);
CactusSemi 4:1c48c9fa44fc 40 pc.printf("\n\n\r\t 7. adc_time_out = 0x%2.2X",*adc_time_out);
CactusSemi 4:1c48c9fa44fc 41 pc.printf("\n\n\r\t 8. comp_offset = 0x%2.2X",*comp_offset);
CactusSemi 4:1c48c9fa44fc 42 pc.printf("\n\n\r\t 9. range_trim = 0x%2.2X",*range_trim);
CactusSemi 4:1c48c9fa44fc 43 pc.printf("\n\n\r\t 10. PMOS_off = 0x%2.2X",*PMOS_off);
CactusSemi 4:1c48c9fa44fc 44 pc.printf("\n\n\r\t 13. SkipPwr = 0x%2.2X",*neg_hlf_rng);
CactusSemi 4:1c48c9fa44fc 45 pc.printf("\n\n\r\t 16. adc_op_mode = 0x%2.2X",*adc_op_mode);
CactusSemi 4:1c48c9fa44fc 46 pc.printf("\n\n\r\t ");
CactusSemi 4:1c48c9fa44fc 47 }
CactusSemi 4:1c48c9fa44fc 48 else
CactusSemi 4:1c48c9fa44fc 49 {
CactusSemi 4:1c48c9fa44fc 50 pc.printf("\n\n\r\t\t BiP Mode \n\n");
CactusSemi 4:1c48c9fa44fc 51 pc.printf("\n\n\r\t 1. max_Vout = 0x%2.2X",*max_Vout);
CactusSemi 4:1c48c9fa44fc 52 pc.printf("\n\n\r\t 2. max_Vout_trim = 0x%2.2X",*max_Vout_trim);
CactusSemi 4:1c48c9fa44fc 53 pc.printf("\n\n\r\t 3. high_time = 0x%2.2X",*high_time);
CactusSemi 4:1c48c9fa44fc 54 pc.printf("\n\n\r\t 4. low_time = 0x%2.2X",*low_time);
CactusSemi 4:1c48c9fa44fc 55 pc.printf("\n\n\r\t 5. adc_samp_rate = 0x%2.2X",*adc_samp_rate);
CactusSemi 4:1c48c9fa44fc 56 pc.printf("\n\n\r\t 6. adc_range = 0x%2.2X",*adc_range);
CactusSemi 4:1c48c9fa44fc 57 pc.printf("\n\n\r\t 7. adc_time_out = 0x%2.2X",*adc_time_out);
CactusSemi 4:1c48c9fa44fc 58 pc.printf("\n\n\r\t 8. comp_offset = 0x%2.2X",*comp_offset);
CactusSemi 4:1c48c9fa44fc 59 pc.printf("\n\n\r\t 9. range_trim = 0x%2.2X",*range_trim);
CactusSemi 4:1c48c9fa44fc 60 pc.printf("\n\n\r\t 10. PMOS_off = 0x%2.2X",*PMOS_off);
CactusSemi 4:1c48c9fa44fc 61 pc.printf("\n\n\r\t 11. Driver2 = 0x%2.2X",*Driver2);
CactusSemi 4:1c48c9fa44fc 62 pc.printf("\n\n\r\t 12. Driver3 = 0x%2.2X",*Driver3);
CactusSemi 4:1c48c9fa44fc 63 pc.printf("\n\n\r\t 13. neg_hlf_rng = 0x%2.2X",*neg_hlf_rng);
CactusSemi 4:1c48c9fa44fc 64 pc.printf("\n\n\r\t 14. CCM_threshold = 0x%2.2X",*CCM_threshold);
CactusSemi 4:1c48c9fa44fc 65 pc.printf("\n\n\r\t 15. DMOS_ctrl_trim = 0x%2.2X",*DMOS_ctrl_trim);
CactusSemi 4:1c48c9fa44fc 66 pc.printf("\n\n\r\t 16. adc_op_mode = 0x%2.2X",*adc_op_mode);
CactusSemi 4:1c48c9fa44fc 67 pc.printf("\n\n\r\t ");
CactusSemi 4:1c48c9fa44fc 68 }
CactusSemi 3:3e8c16b6620c 69 for ( int i = 0; i<26; i++) pc.printf("\315");
CactusSemi 3:3e8c16b6620c 70 pc.printf("\033[%dm", 32);//change text color to green
CactusSemi 3:3e8c16b6620c 71 pc.printf("\n\r");
CactusSemi 3:3e8c16b6620c 72 }
CactusSemi 3:3e8c16b6620c 73
CactusSemi 3:3e8c16b6620c 74 void edit_nvm_reg(uint8_t *max_Vout, uint8_t *max_Vout_trim, uint8_t *high_time, uint8_t *low_time, uint8_t *adc_samp_rate,
CactusSemi 3:3e8c16b6620c 75 uint8_t *adc_range, uint8_t *adc_time_out, uint8_t *comp_offset, uint8_t *range_trim, uint8_t *PMOS_off, uint8_t *Driver2, uint8_t *Driver3,
CactusSemi 4:1c48c9fa44fc 76 uint8_t *neg_hlf_rng, uint8_t *CCM_threshold, uint8_t *DMOS_ctrl_trim, uint8_t *adc_op_mode) {
CactusSemi 3:3e8c16b6620c 77
CactusSemi 3:3e8c16b6620c 78 char temp;
CactusSemi 3:3e8c16b6620c 79 int flag1;
CactusSemi 3:3e8c16b6620c 80 char count;
CactusSemi 3:3e8c16b6620c 81 char reg_data;
CactusSemi 3:3e8c16b6620c 82
CactusSemi 4:1c48c9fa44fc 83 char reg_name[16][20] = {"max_Vout", "max_Vout_trim", "high_time", "low_time", "adc_samp_rate",
CactusSemi 3:3e8c16b6620c 84 "adc_range", "adc_time_out", "comp_offset", "range_trim", "PMOS_off", "Driver2", "Driver3",
CactusSemi 4:1c48c9fa44fc 85 "neg_hlf_rng_SkipPwr", "CCM_threshold", "DMOS_ctrl_trim", "adc_op_mode" };
CactusSemi 3:3e8c16b6620c 86
CactusSemi 3:3e8c16b6620c 87 uint8_t *reg_addr[16] = { max_Vout, max_Vout_trim, high_time, low_time, adc_samp_rate,
CactusSemi 3:3e8c16b6620c 88 adc_range, adc_time_out, comp_offset, range_trim, PMOS_off, Driver2, Driver3,
CactusSemi 4:1c48c9fa44fc 89 neg_hlf_rng, CCM_threshold, DMOS_ctrl_trim, adc_op_mode};
CactusSemi 3:3e8c16b6620c 90
CactusSemi 3:3e8c16b6620c 91 pc.printf("\n\n\n \r\tDo you want to edit the registers? (y/n) : ");
CactusSemi 3:3e8c16b6620c 92 temp = 0;
CactusSemi 3:3e8c16b6620c 93 while ( temp!='y' && temp!='n') {
CactusSemi 3:3e8c16b6620c 94 temp = pc.getc();
CactusSemi 3:3e8c16b6620c 95 }
CactusSemi 3:3e8c16b6620c 96 if (temp == 'n') {
CactusSemi 4:1c48c9fa44fc 97 pc.printf("\n\n \r\tContinuing with above contents");
CactusSemi 3:3e8c16b6620c 98 return;
CactusSemi 3:3e8c16b6620c 99 }
CactusSemi 3:3e8c16b6620c 100 temp = 'y';
CactusSemi 3:3e8c16b6620c 101 while (temp =='y') {
CactusSemi 3:3e8c16b6620c 102 //get selection
CactusSemi 3:3e8c16b6620c 103 flag1 = 0;
CactusSemi 3:3e8c16b6620c 104 while (!flag1) {
CactusSemi 3:3e8c16b6620c 105 pc.printf("\n\n\n\r\tEnter (1 - 16) to select the register to edit and hit 'enter' key: ");
CactusSemi 3:3e8c16b6620c 106 temp = '0';
CactusSemi 3:3e8c16b6620c 107 count = 0;
CactusSemi 3:3e8c16b6620c 108 while (temp != '\r') { //look for enter key
CactusSemi 3:3e8c16b6620c 109 count = (count * 10) + (temp - '0'); // converting to number
CactusSemi 3:3e8c16b6620c 110 temp = pc.getc();
CactusSemi 3:3e8c16b6620c 111 if ((temp < '0' || temp > '9') && temp !='\r') {
CactusSemi 3:3e8c16b6620c 112 pc.printf(" \n\r\t\033[%dm Invalid Chracter!! No worries, let us try again \033[%dm",41,40);
CactusSemi 3:3e8c16b6620c 113 break;
CactusSemi 3:3e8c16b6620c 114 }
CactusSemi 3:3e8c16b6620c 115 }
CactusSemi 3:3e8c16b6620c 116 if (count >= 1 && count <= 16 && temp == '\r') flag1 = 1;
CactusSemi 3:3e8c16b6620c 117 else if (temp == '\r') pc.printf(" \n\r\t\033[%dm Invalid Chracter!! No worries, let us try again \033[%dm",41,40);
CactusSemi 3:3e8c16b6620c 118 }
CactusSemi 3:3e8c16b6620c 119 count = count - 1; //array starts from 0
CactusSemi 3:3e8c16b6620c 120 //Read New Register Data
CactusSemi 3:3e8c16b6620c 121 flag1 = 0;
CactusSemi 3:3e8c16b6620c 122 while (!flag1) {
CactusSemi 3:3e8c16b6620c 123 pc.printf("\n\n \r\tEnter new value in hex (00 to ff) for \033[%dm %s \033[%dm register : ",35,reg_name[count],32);
CactusSemi 3:3e8c16b6620c 124 reg_data = get_half_byte(&flag1);
CactusSemi 3:3e8c16b6620c 125 if (flag1 == 1) {
CactusSemi 3:3e8c16b6620c 126 reg_data = reg_data << 4;
CactusSemi 3:3e8c16b6620c 127 temp = get_half_byte(&flag1);
CactusSemi 3:3e8c16b6620c 128 reg_data = (reg_data | temp);
CactusSemi 3:3e8c16b6620c 129 }
CactusSemi 3:3e8c16b6620c 130 if (flag1==0) pc.printf(" \033[%dm Invalid Chracter!! No worries, let us try again \033[%dm",41,40);
CactusSemi 3:3e8c16b6620c 131 }
CactusSemi 3:3e8c16b6620c 132 *(reg_addr[count]) = reg_data;
CactusSemi 3:3e8c16b6620c 133
CactusSemi 3:3e8c16b6620c 134 print_nvm_reg( max_Vout, max_Vout_trim, high_time, low_time, adc_samp_rate,
CactusSemi 3:3e8c16b6620c 135 adc_range, adc_time_out, comp_offset, range_trim, PMOS_off, Driver2, Driver3,
CactusSemi 4:1c48c9fa44fc 136 neg_hlf_rng, CCM_threshold, DMOS_ctrl_trim, adc_op_mode);
CactusSemi 3:3e8c16b6620c 137
CactusSemi 3:3e8c16b6620c 138 pc.printf("\n\n \r\tDo you want to make more changes? (y/n) : ");
CactusSemi 3:3e8c16b6620c 139 temp = pc.getc();
CactusSemi 3:3e8c16b6620c 140 } //end of edit while loop
CactusSemi 3:3e8c16b6620c 141 }
CactusSemi 3:3e8c16b6620c 142
CactusSemi 3:3e8c16b6620c 143 void i2c_write_fn(I2C *i2c_obj, char ptr, char write_data) {
CactusSemi 3:3e8c16b6620c 144 int flag1;
CactusSemi 4:1c48c9fa44fc 145 wait_us(20);
CactusSemi 3:3e8c16b6620c 146 (*i2c_obj).start();
CactusSemi 3:3e8c16b6620c 147 flag1 = (*i2c_obj).write(dev_addr);
CactusSemi 3:3e8c16b6620c 148 if (flag1 != 1) pc.printf("\n\n\r\tNo Ack for dev addr :(");
CactusSemi 3:3e8c16b6620c 149 flag1 = (*i2c_obj).write(ptr);
CactusSemi 3:3e8c16b6620c 150 if (flag1 != 1) pc.printf("\n\n\r\tNo Ack reg pointer :(");
CactusSemi 3:3e8c16b6620c 151 flag1 = (*i2c_obj).write(write_data);
CactusSemi 3:3e8c16b6620c 152 if (flag1 != 1) pc.printf("\n\n\r\tNo Ack data :(");
CactusSemi 4:1c48c9fa44fc 153 wait_us(20);
CactusSemi 3:3e8c16b6620c 154 (*i2c_obj).stop();
CactusSemi 4:1c48c9fa44fc 155 wait_us(300);
CactusSemi 3:3e8c16b6620c 156 }
CactusSemi 3:3e8c16b6620c 157
CactusSemi 3:3e8c16b6620c 158 char i2c_read_fn(I2C *i2c_obj, char ptr) {
CactusSemi 3:3e8c16b6620c 159 int flag1;
CactusSemi 3:3e8c16b6620c 160 char read_data;
CactusSemi 3:3e8c16b6620c 161 wait_us(10);
CactusSemi 3:3e8c16b6620c 162 (*i2c_obj).start();
CactusSemi 3:3e8c16b6620c 163 flag1 = (*i2c_obj).write(dev_addr);
CactusSemi 3:3e8c16b6620c 164 if (flag1 != 1) pc.printf("\n\n\n\r\tNo Ack for dev addr :(");
CactusSemi 3:3e8c16b6620c 165 flag1 = (*i2c_obj).write(ptr);
CactusSemi 3:3e8c16b6620c 166 if (flag1 != 1) pc.printf("\n\n\r\tNo Ack reg pointer :(");
CactusSemi 3:3e8c16b6620c 167 (*i2c_obj).stop();
CactusSemi 4:1c48c9fa44fc 168 wait_us(300);
CactusSemi 3:3e8c16b6620c 169 (*i2c_obj).start();
CactusSemi 3:3e8c16b6620c 170 flag1 = (*i2c_obj).write(dev_addr | 0x01); //lsb 1 for read
CactusSemi 3:3e8c16b6620c 171 if (flag1 != 1) pc.printf("\n\n\r\tNo Ack for dev addr :(");
CactusSemi 3:3e8c16b6620c 172 read_data = (*i2c_obj).read(0); //0- donot send ack after read is done
CactusSemi 3:3e8c16b6620c 173 wait_us(5);
CactusSemi 3:3e8c16b6620c 174 (*i2c_obj).stop();
CactusSemi 4:1c48c9fa44fc 175 wait_us(300);
CactusSemi 3:3e8c16b6620c 176 return read_data;
CactusSemi 3:3e8c16b6620c 177 }
CactusSemi 3:3e8c16b6620c 178
CactusSemi 3:3e8c16b6620c 179 uint64_t EasyFuse_read(I2C *i2c_obj) {
CactusSemi 3:3e8c16b6620c 180 char reg_ptr = 0x00;
CactusSemi 3:3e8c16b6620c 181 char reg_data[10];
CactusSemi 3:3e8c16b6620c 182 char data;
CactusSemi 4:1c48c9fa44fc 183 uint8_t NVM_PWR_ON = 0x20 ;
CactusSemi 4:1c48c9fa44fc 184 uint8_t NVM_READ = 0x90 ; //force load shadow register
CactusSemi 3:3e8c16b6620c 185 uint8_t NVM_CTLR_ADR = 0x0a ; //Register address for NVM CTRL
CactusSemi 3:3e8c16b6620c 186 uint64_t NVM_data = 0x0000000000000000;
CactusSemi 3:3e8c16b6620c 187
CactusSemi 3:3e8c16b6620c 188 //Variables to store read data
CactusSemi 3:3e8c16b6620c 189 uint8_t max_Vout;
CactusSemi 3:3e8c16b6620c 190 uint8_t max_Vout_trim;
CactusSemi 3:3e8c16b6620c 191 uint8_t high_time;
CactusSemi 3:3e8c16b6620c 192 uint8_t low_time;
CactusSemi 3:3e8c16b6620c 193 uint8_t adc_samp_rate;
CactusSemi 3:3e8c16b6620c 194 uint8_t adc_range;
CactusSemi 3:3e8c16b6620c 195 uint8_t adc_time_out;
CactusSemi 3:3e8c16b6620c 196 uint8_t comp_offset;
CactusSemi 3:3e8c16b6620c 197 uint8_t range_trim;
CactusSemi 3:3e8c16b6620c 198 uint8_t PMOS_off;
CactusSemi 3:3e8c16b6620c 199 uint8_t Driver2;
CactusSemi 3:3e8c16b6620c 200 uint8_t Driver3;
CactusSemi 4:1c48c9fa44fc 201 uint8_t neg_hlf_rng;
CactusSemi 3:3e8c16b6620c 202 uint8_t CCM_threshold;
CactusSemi 3:3e8c16b6620c 203 uint8_t DMOS_ctrl_trim;
CactusSemi 3:3e8c16b6620c 204 uint8_t adc_op_mode;
CactusSemi 3:3e8c16b6620c 205
CactusSemi 3:3e8c16b6620c 206 int i;
CactusSemi 3:3e8c16b6620c 207 char temp;
CactusSemi 3:3e8c16b6620c 208
CactusSemi 3:3e8c16b6620c 209 pc.printf("\n\n\n\r\t");
CactusSemi 3:3e8c16b6620c 210 for ( i = 0; i<60; i++) pc.printf("\304");
CactusSemi 3:3e8c16b6620c 211 pc.printf("\n\n\n\r\tPerforming an NVM read and loading the contents to the register");
CactusSemi 3:3e8c16b6620c 212 pc.printf("\n\n\r\tSwitching to faster clock before reading the NVM");
CactusSemi 3:3e8c16b6620c 213 i2c_write_fn(i2c_obj,0x02,0x01); //switching to faster clock for NVM read
CactusSemi 3:3e8c16b6620c 214 i2c_write_fn(i2c_obj,0x03,0x01); //switching to faster clock for NVM read
CactusSemi 4:1c48c9fa44fc 215 i2c_write_fn(i2c_obj,NVM_CTLR_ADR,NVM_PWR_ON);
CactusSemi 3:3e8c16b6620c 216 wait_ms(1);
CactusSemi 4:1c48c9fa44fc 217 i2c_write_fn(i2c_obj,NVM_CTLR_ADR,(NVM_PWR_ON + NVM_READ)); //Force load shadow register from NVM
CactusSemi 4:1c48c9fa44fc 218 wait_ms(200);
CactusSemi 3:3e8c16b6620c 219
CactusSemi 3:3e8c16b6620c 220 pc.printf("\n\n\n\r\tReading register 0x00 to 0x09");
CactusSemi 3:3e8c16b6620c 221 for( reg_ptr = 0x00; reg_ptr <= 0x09; reg_ptr = reg_ptr+1) {
CactusSemi 3:3e8c16b6620c 222 reg_data[reg_ptr] = i2c_read_fn(i2c_obj,reg_ptr);
CactusSemi 3:3e8c16b6620c 223 }
CactusSemi 3:3e8c16b6620c 224
CactusSemi 3:3e8c16b6620c 225 //Storing read data into variables
CactusSemi 3:3e8c16b6620c 226 max_Vout = reg_data[0] & 0x0f;
CactusSemi 3:3e8c16b6620c 227 max_Vout_trim = reg_data[1] & 0x1f;
CactusSemi 3:3e8c16b6620c 228 high_time = reg_data[2] & 0x7f;
CactusSemi 3:3e8c16b6620c 229 low_time = reg_data[3] & 0x7f;
CactusSemi 3:3e8c16b6620c 230 adc_samp_rate = reg_data[4]>>4;
CactusSemi 3:3e8c16b6620c 231 adc_range = (reg_data[4]>>2) & 0x03;
CactusSemi 3:3e8c16b6620c 232 adc_time_out = reg_data[4] & 0x03;
CactusSemi 3:3e8c16b6620c 233 comp_offset = reg_data[5] & 0x1f;
CactusSemi 3:3e8c16b6620c 234 range_trim = reg_data[6] & 0x1f;
CactusSemi 3:3e8c16b6620c 235 PMOS_off = reg_data[7] & 0x0f;
CactusSemi 3:3e8c16b6620c 236 Driver2 = reg_data[8] & 0x0f;
CactusSemi 3:3e8c16b6620c 237 Driver3 = (reg_data[8]>>4) & 0x0f;
CactusSemi 4:1c48c9fa44fc 238 neg_hlf_rng = (reg_data[9]>>7) & 0x01;
CactusSemi 3:3e8c16b6620c 239 CCM_threshold = (reg_data[7]>>4) & 0x0f;
CactusSemi 3:3e8c16b6620c 240 DMOS_ctrl_trim = reg_data[9] & 0x1f;
CactusSemi 3:3e8c16b6620c 241 adc_op_mode = (reg_data[5]>>7) & 0x01;
CactusSemi 3:3e8c16b6620c 242
CactusSemi 3:3e8c16b6620c 243 pc.printf("\n\n\r\tFollowing data was read from the Register");
CactusSemi 3:3e8c16b6620c 244
CactusSemi 3:3e8c16b6620c 245 print_nvm_reg(&max_Vout, &max_Vout_trim, &high_time, &low_time, &adc_samp_rate,
CactusSemi 3:3e8c16b6620c 246 &adc_range, &adc_time_out, &comp_offset, &range_trim, &PMOS_off, &Driver2, &Driver3,
CactusSemi 4:1c48c9fa44fc 247 &neg_hlf_rng, &CCM_threshold, &DMOS_ctrl_trim, &adc_op_mode);
CactusSemi 3:3e8c16b6620c 248
CactusSemi 3:3e8c16b6620c 249 //push data into NVM_data
CactusSemi 4:1c48c9fa44fc 250 NVM_data = NVM_data | (max_Vout); //max_Vout(register) = max_Vout(NVM) - 1// this needs to be changed
CactusSemi 3:3e8c16b6620c 251 NVM_data = (NVM_data<<5) | max_Vout_trim;
CactusSemi 3:3e8c16b6620c 252 NVM_data = (NVM_data<<7) | high_time; // <<x : x corresponds to no. of bits
CactusSemi 3:3e8c16b6620c 253 NVM_data = (NVM_data<<7) | low_time;
CactusSemi 3:3e8c16b6620c 254 NVM_data = (NVM_data<<4) | adc_samp_rate;
CactusSemi 3:3e8c16b6620c 255 NVM_data = (NVM_data<<2) | adc_range;
CactusSemi 3:3e8c16b6620c 256 NVM_data = (NVM_data<<2) | adc_time_out;
CactusSemi 3:3e8c16b6620c 257 NVM_data = (NVM_data<<5) | comp_offset;
CactusSemi 3:3e8c16b6620c 258 NVM_data = (NVM_data<<5) | range_trim;
CactusSemi 3:3e8c16b6620c 259 NVM_data = (NVM_data<<4) | PMOS_off;
CactusSemi 3:3e8c16b6620c 260 NVM_data = (NVM_data<<4) | Driver2;
CactusSemi 3:3e8c16b6620c 261 NVM_data = (NVM_data<<4) | Driver3;
CactusSemi 4:1c48c9fa44fc 262 NVM_data = (NVM_data<<1) | neg_hlf_rng;
CactusSemi 3:3e8c16b6620c 263 NVM_data = (NVM_data<<4) | CCM_threshold;
CactusSemi 3:3e8c16b6620c 264 NVM_data = (NVM_data<<5) | DMOS_ctrl_trim;
CactusSemi 3:3e8c16b6620c 265 NVM_data = (NVM_data<<1) | adc_op_mode;
CactusSemi 3:3e8c16b6620c 266
CactusSemi 3:3e8c16b6620c 267 pc.printf("\n\n\n\r\tReconstructed data read from NVM = 0x%016llX",NVM_data);
CactusSemi 3:3e8c16b6620c 268 return NVM_data;
CactusSemi 3:3e8c16b6620c 269 }
CactusSemi 3:3e8c16b6620c 270
CactusSemi 3:3e8c16b6620c 271
CactusSemi 3:3e8c16b6620c 272 void EasyFuse_prog() {
CactusSemi 3:3e8c16b6620c 273 uint64_t NVM_data = 0x0000000000000000;
CactusSemi 3:3e8c16b6620c 274 uint64_t NVM_read_data;
CactusSemi 3:3e8c16b6620c 275
CactusSemi 3:3e8c16b6620c 276 // Register variables
CactusSemi 4:1c48c9fa44fc 277 uint8_t max_Vout = 0x00; //4.2V
CactusSemi 4:1c48c9fa44fc 278 uint8_t max_Vout_trim = 0x03; //0%
CactusSemi 4:1c48c9fa44fc 279 uint8_t high_time = 0x11; //12us
CactusSemi 4:1c48c9fa44fc 280 uint8_t low_time = 0x46; //38us
CactusSemi 4:1c48c9fa44fc 281 uint8_t adc_samp_rate = 0x05; //1 sample/1.35s
CactusSemi 4:1c48c9fa44fc 282 uint8_t adc_range = 0x01; //2mV
CactusSemi 4:1c48c9fa44fc 283 uint8_t adc_time_out = 0x02; // 1/256 = 5.3ms
CactusSemi 4:1c48c9fa44fc 284 uint8_t comp_offset = 0x00; //0%
CactusSemi 4:1c48c9fa44fc 285 uint8_t range_trim = 0x16; //0%
CactusSemi 4:1c48c9fa44fc 286 uint8_t PMOS_off = 0x07; //7 -> 18mV
CactusSemi 4:1c48c9fa44fc 287 uint8_t Driver2 = 0x08; //8 -> 36mV
CactusSemi 4:1c48c9fa44fc 288 uint8_t Driver3 = 0x08; // 8 -> 54mV
CactusSemi 4:1c48c9fa44fc 289 uint8_t neg_hlf_rng = 0x00; //disabled
CactusSemi 4:1c48c9fa44fc 290 uint8_t CCM_threshold = 0x00; //off
CactusSemi 4:1c48c9fa44fc 291 uint8_t DMOS_ctrl_trim = 0x16; //<14us
CactusSemi 4:1c48c9fa44fc 292 uint8_t adc_op_mode = 0x00; //Transmit measurements continously
CactusSemi 3:3e8c16b6620c 293
CactusSemi 4:1c48c9fa44fc 294 // NVM Register Control Bit locations;
CactusSemi 4:1c48c9fa44fc 295 uint8_t NVM_RESET = 0x01 ;
CactusSemi 3:3e8c16b6620c 296 uint8_t NVM_PWE1 = 0x02 ;
CactusSemi 4:1c48c9fa44fc 297 uint8_t NVM_CLK1 = 0x04 ;
CactusSemi 4:1c48c9fa44fc 298 uint8_t NVM_PWR_ON = 0x20 ;
CactusSemi 4:1c48c9fa44fc 299 uint8_t NVM_LD_SHDW = 0x90 ;//unpdated in Rev1.0
CactusSemi 4:1c48c9fa44fc 300 uint8_t NVM_READ = 0x50 ;
CactusSemi 3:3e8c16b6620c 301
CactusSemi 4:1c48c9fa44fc 302 uint8_t NVM_CTLR_ADR = 0x0a ; //Register address for NVM CTRL
CactusSemi 3:3e8c16b6620c 303
CactusSemi 3:3e8c16b6620c 304 char reg_data = 0xaa;
CactusSemi 3:3e8c16b6620c 305 char temp;
CactusSemi 3:3e8c16b6620c 306 char high_time_prog = 0x04;
CactusSemi 4:1c48c9fa44fc 307 char low_time_prog = 0x05;
CactusSemi 3:3e8c16b6620c 308 int flag1 = 0;
CactusSemi 3:3e8c16b6620c 309 int i = 0;
CactusSemi 3:3e8c16b6620c 310
CactusSemi 3:3e8c16b6620c 311 int delay1 = 20;
CactusSemi 3:3e8c16b6620c 312 int delay2 = 2 * delay1;
CactusSemi 3:3e8c16b6620c 313
CactusSemi 3:3e8c16b6620c 314 I2C i2c(p9,p10);
CactusSemi 3:3e8c16b6620c 315 i2c.frequency((frequ/2)*1000);
CactusSemi 3:3e8c16b6620c 316 LPC_PINCON->PINMODE_OD0 = (LPC_PINCON->PINMODE_OD0 | 0x0003); // To make p9 & P10 open_drain
CactusSemi 3:3e8c16b6620c 317 i2c.stop(); //add a stop after hot-read
CactusSemi 3:3e8c16b6620c 318
CactusSemi 3:3e8c16b6620c 319 pc.printf("\n\n\r\tFollowing are the default register data that will be programmed: \n\r ");
CactusSemi 3:3e8c16b6620c 320 print_nvm_reg(&max_Vout, &max_Vout_trim, &high_time, &low_time, &adc_samp_rate,
CactusSemi 3:3e8c16b6620c 321 &adc_range, &adc_time_out, &comp_offset, &range_trim, &PMOS_off, &Driver2, &Driver3,
CactusSemi 4:1c48c9fa44fc 322 &neg_hlf_rng, &CCM_threshold, &DMOS_ctrl_trim, &adc_op_mode);
CactusSemi 3:3e8c16b6620c 323
CactusSemi 3:3e8c16b6620c 324 edit_nvm_reg(&max_Vout, &max_Vout_trim, &high_time, &low_time, &adc_samp_rate,
CactusSemi 3:3e8c16b6620c 325 &adc_range, &adc_time_out, &comp_offset, &range_trim, &PMOS_off, &Driver2, &Driver3,
CactusSemi 4:1c48c9fa44fc 326 &neg_hlf_rng, &CCM_threshold, &DMOS_ctrl_trim, &adc_op_mode);
CactusSemi 3:3e8c16b6620c 327
CactusSemi 3:3e8c16b6620c 328 //push data into NVM_data
CactusSemi 4:1c48c9fa44fc 329 NVM_data = NVM_data | max_Vout; //no more addition of 1 as in Jacaranda
CactusSemi 3:3e8c16b6620c 330 NVM_data = (NVM_data<<5) | max_Vout_trim;
CactusSemi 3:3e8c16b6620c 331 NVM_data = (NVM_data<<7) | high_time; // <<x : x corresponds to no. of bits
CactusSemi 3:3e8c16b6620c 332 NVM_data = (NVM_data<<7) | low_time;
CactusSemi 3:3e8c16b6620c 333 NVM_data = (NVM_data<<4) | adc_samp_rate;
CactusSemi 3:3e8c16b6620c 334 NVM_data = (NVM_data<<2) | adc_range;
CactusSemi 3:3e8c16b6620c 335 NVM_data = (NVM_data<<2) | adc_time_out;
CactusSemi 3:3e8c16b6620c 336 NVM_data = (NVM_data<<5) | comp_offset;
CactusSemi 3:3e8c16b6620c 337 NVM_data = (NVM_data<<5) | range_trim;
CactusSemi 3:3e8c16b6620c 338 NVM_data = (NVM_data<<4) | PMOS_off;
CactusSemi 3:3e8c16b6620c 339 NVM_data = (NVM_data<<4) | Driver2;
CactusSemi 3:3e8c16b6620c 340 NVM_data = (NVM_data<<4) | Driver3;
CactusSemi 4:1c48c9fa44fc 341 NVM_data = (NVM_data<<1) | neg_hlf_rng;
CactusSemi 3:3e8c16b6620c 342 NVM_data = (NVM_data<<4) | CCM_threshold;
CactusSemi 3:3e8c16b6620c 343 NVM_data = (NVM_data<<5) | DMOS_ctrl_trim;
CactusSemi 3:3e8c16b6620c 344 NVM_data = (NVM_data<<1) | adc_op_mode;
CactusSemi 3:3e8c16b6620c 345 pc.printf("\n\n\n\r\tData to be written into NVM = 0x%016llX",NVM_data);
CactusSemi 3:3e8c16b6620c 346 pc.printf("\n\n\r\t");
CactusSemi 3:3e8c16b6620c 347 for ( i = 0; i<80; i++) pc.printf("\304");
CactusSemi 3:3e8c16b6620c 348 pc.printf("\n\n\r\tContinue EasyFuse Programming? (y/n): ");
CactusSemi 3:3e8c16b6620c 349 temp = 0;
CactusSemi 3:3e8c16b6620c 350 while ( temp!='y' && temp!='n') {
CactusSemi 3:3e8c16b6620c 351 temp = pc.getc();
CactusSemi 3:3e8c16b6620c 352 }
CactusSemi 3:3e8c16b6620c 353 if (temp == 'n') {
CactusSemi 3:3e8c16b6620c 354 pc.printf("\n\n\r\tAborting... :(");
CactusSemi 3:3e8c16b6620c 355 return;
CactusSemi 3:3e8c16b6620c 356 }
CactusSemi 4:1c48c9fa44fc 357 temp = 0;
CactusSemi 4:1c48c9fa44fc 358 pc.printf("\n\n\n\r\tConnect PROG to 4.5V & VINA to 4.5V and press 'c' to continue");
CactusSemi 4:1c48c9fa44fc 359 while ( temp!='c') {
CactusSemi 4:1c48c9fa44fc 360 temp = pc.getc();
CactusSemi 4:1c48c9fa44fc 361 }
CactusSemi 3:3e8c16b6620c 362 //EasyFuse Empty check
CactusSemi 4:1c48c9fa44fc 363 pc.printf("\n\n\r\tPerforming NVM Empty check by trying to load register with NVM contents.");
CactusSemi 3:3e8c16b6620c 364 i2c_write_fn(&i2c,0x02,0x01); //switching to faster clock for NVM read
CactusSemi 3:3e8c16b6620c 365 i2c_write_fn(&i2c,0x03,0x01); //switching to faster clock for NVM read
CactusSemi 3:3e8c16b6620c 366 wait_ms(1);
CactusSemi 4:1c48c9fa44fc 367 i2c_write_fn(&i2c,NVM_CTLR_ADR,NVM_PWR_ON);
CactusSemi 4:1c48c9fa44fc 368 wait_ms(1);
CactusSemi 4:1c48c9fa44fc 369 i2c_write_fn(&i2c,NVM_CTLR_ADR,(NVM_READ + NVM_PWR_ON)); //Initiate NVM read cycle
CactusSemi 4:1c48c9fa44fc 370 wait_ms(200);
CactusSemi 4:1c48c9fa44fc 371
CactusSemi 3:3e8c16b6620c 372 reg_data = i2c_read_fn(&i2c,0x02);
CactusSemi 3:3e8c16b6620c 373 reg_data = reg_data<<4;
CactusSemi 3:3e8c16b6620c 374 reg_data = reg_data | i2c_read_fn(&i2c,0x03);
CactusSemi 3:3e8c16b6620c 375 if (reg_data == 0xff) pc.printf(" |\033[%dm Register read might not be sucessfull \033[%dm ",45,40);
CactusSemi 4:1c48c9fa44fc 376 if (reg_data == 0x11) pc.printf("\n\n\r\t\033[%dm EasyFuse empty \033[%dm",44,40); //NVM load will be successful only when NVM is not empty
CactusSemi 3:3e8c16b6620c 377 else {
CactusSemi 3:3e8c16b6620c 378 pc.printf("\n\n\r\t\033[%dm EasyFuse not empty \033[%dm",45,40);
CactusSemi 3:3e8c16b6620c 379 pc.printf("\n\n\r\t Better to abort the test.. :(");
CactusSemi 3:3e8c16b6620c 380 //return;
CactusSemi 3:3e8c16b6620c 381 }
CactusSemi 3:3e8c16b6620c 382
CactusSemi 3:3e8c16b6620c 383 //added for debug.. delete later
CactusSemi 3:3e8c16b6620c 384 pc.printf("\n\n\n\r\tWe will next configure the oscillator. Proceed? (y/n): ");
CactusSemi 3:3e8c16b6620c 385 temp = 0;
CactusSemi 3:3e8c16b6620c 386 while ( temp!='y' && temp!='n') {
CactusSemi 3:3e8c16b6620c 387 temp = pc.getc();
CactusSemi 3:3e8c16b6620c 388 }
CactusSemi 3:3e8c16b6620c 389 if (temp == 'n') {
CactusSemi 3:3e8c16b6620c 390 pc.printf("\n\n\r\tAborting.. :(");
CactusSemi 3:3e8c16b6620c 391 return;
CactusSemi 3:3e8c16b6620c 392 }
CactusSemi 4:1c48c9fa44fc 393
CactusSemi 4:1c48c9fa44fc 394 i2c_write_fn(&i2c,0x17,0x01); //internal clock is muxed out through DATA2_CLK
CactusSemi 4:1c48c9fa44fc 395 pc.printf("\n\n\r\tMonitor Clock at DATA2_CLK pin");
CactusSemi 4:1c48c9fa44fc 396
CactusSemi 3:3e8c16b6620c 397 osc_trim:
CactusSemi 3:3e8c16b6620c 398 i2c_write_fn(&i2c,0x02,high_time_prog); //Recommended clocks period
CactusSemi 3:3e8c16b6620c 399 i2c_write_fn(&i2c,0x03,low_time_prog); // for programming is 10us
CactusSemi 3:3e8c16b6620c 400 wait_ms(1);
CactusSemi 3:3e8c16b6620c 401
CactusSemi 3:3e8c16b6620c 402 pc.printf("\n\n\n\r\t\033[%dm", 44);//change backround to blue
CactusSemi 4:1c48c9fa44fc 403 pc.printf("Please check if Oscillator period is approx 10us (9.5us to 10.5us) \033[%dm\n\n\r\tPress 'y' to continue; Press 'm' to modify clock trim settings : ",40);
CactusSemi 3:3e8c16b6620c 404
CactusSemi 3:3e8c16b6620c 405 temp = 0;
CactusSemi 4:1c48c9fa44fc 406 while ( temp!='y' && temp!='m' && temp!='n' ) {
CactusSemi 3:3e8c16b6620c 407 temp = pc.getc();
CactusSemi 3:3e8c16b6620c 408 }
CactusSemi 3:3e8c16b6620c 409 if (temp == 'n') {
CactusSemi 3:3e8c16b6620c 410 pc.printf("\n\n\r\tAborting.. :(");
CactusSemi 3:3e8c16b6620c 411 return;
CactusSemi 3:3e8c16b6620c 412 }
CactusSemi 3:3e8c16b6620c 413 if (temp == 'm') {
CactusSemi 3:3e8c16b6620c 414 pc.printf("\n\n\n\n\r\tCurrent high_time trim = 0x%2.2X & low_time trim = 0x%2.2X",high_time_prog,low_time_prog);
CactusSemi 4:1c48c9fa44fc 415 pc.printf("\n\n\r\tSuggestion - Change high_trim first then low_trim");
CactusSemi 3:3e8c16b6620c 416 flag1 = 0;
CactusSemi 3:3e8c16b6620c 417 while (!flag1) {
CactusSemi 3:3e8c16b6620c 418 pc.printf("\n\n\r\tEnter new high_time trim in hex (00 to ff): 0x");
CactusSemi 3:3e8c16b6620c 419 high_time_prog = get_byte(&flag1);
CactusSemi 3:3e8c16b6620c 420 if (flag1 == 0) pc.printf(" \033[%dm Invalid Chracter!! No worries, let us try again \033[%dm",41,40);
CactusSemi 3:3e8c16b6620c 421 }
CactusSemi 3:3e8c16b6620c 422 flag1 = 0;
CactusSemi 3:3e8c16b6620c 423 while (!flag1) {
CactusSemi 3:3e8c16b6620c 424 pc.printf("\n\n\r\tEnter new low_time trim in hex (00 to ff) : 0x");
CactusSemi 3:3e8c16b6620c 425 low_time_prog = get_byte(&flag1);
CactusSemi 3:3e8c16b6620c 426 if (flag1 == 0) pc.printf(" \033[%dm Invalid Chracter!! No worries, let us try again \033[%dm",41,40);
CactusSemi 3:3e8c16b6620c 427 }
CactusSemi 3:3e8c16b6620c 428 pc.printf("\n\n\r\tProgramming new high_time trim = 0x%2.2X & new low_time trim = 0x%2.2X",high_time_prog,low_time_prog);
CactusSemi 3:3e8c16b6620c 429 goto osc_trim;
CactusSemi 3:3e8c16b6620c 430 }
CactusSemi 4:1c48c9fa44fc 431 i2c_write_fn(&i2c,0x17,0x00); //DATA2_CLK pulled to GND
CactusSemi 4:1c48c9fa44fc 432 i2c_write_fn(&i2c,0x10,0x04); //tm_ProgSamp_en = 1, needed to disable pull-up device between VINA & PROG
CactusSemi 4:1c48c9fa44fc 433 pc.printf("\n\n\r\tDATA2_CLK pulled low");
CactusSemi 3:3e8c16b6620c 434 wait_ms(delay2);
CactusSemi 3:3e8c16b6620c 435 pc.printf("\n\n\n\r\tAll set to program the EasyFuse, time to blow up some ploy fuses! ..**BOOOM**\n\n\r");
CactusSemi 4:1c48c9fa44fc 436
CactusSemi 4:1c48c9fa44fc 437 temp = 0;
CactusSemi 4:1c48c9fa44fc 438 pc.printf("\n\n\n\r\tConnect PROG to 4.5V & VINA to 5V and press 'c' to continue");
CactusSemi 4:1c48c9fa44fc 439 while ( temp!='c') {
CactusSemi 4:1c48c9fa44fc 440 temp = pc.getc();
CactusSemi 4:1c48c9fa44fc 441 }
CactusSemi 3:3e8c16b6620c 442 i2c_write_fn(&i2c,NVM_CTLR_ADR,NVM_PWR_ON); //turn ON supply to EasyFuse
CactusSemi 3:3e8c16b6620c 443 wait_ms(100);
CactusSemi 4:1c48c9fa44fc 444 i2c_write_fn(&i2c,NVM_CTLR_ADR,(NVM_RESET + NVM_PWR_ON)); //turn ON supply to EasyFuse & RESETN = 1
CactusSemi 3:3e8c16b6620c 445 wait_ms(1);
CactusSemi 3:3e8c16b6620c 446 i2c_write_fn(&i2c,NVM_CTLR_ADR,NVM_PWR_ON); //RESETN = 0, Prog mode enabled: CKL1 = 0 during RESETN = 0,
CactusSemi 4:1c48c9fa44fc 447
CactusSemi 4:1c48c9fa44fc 448 pc.printf("\n\n\n\r\t");
CactusSemi 3:3e8c16b6620c 449 wait_us(delay2);
CactusSemi 4:1c48c9fa44fc 450 i2c_write_fn(&i2c,NVM_CTLR_ADR,(NVM_RESET + NVM_PWR_ON)); //RESETN = 1
CactusSemi 3:3e8c16b6620c 451 wait_us(delay2);
CactusSemi 3:3e8c16b6620c 452 for ( i = 0; i < 64; i = i+1) {
CactusSemi 4:1c48c9fa44fc 453 if ( ((NVM_data>>i) & 0x0000000000000001) == 1 ) {
CactusSemi 4:1c48c9fa44fc 454 temp = NVM_PWE1;
CactusSemi 4:1c48c9fa44fc 455 pc.printf("1");
CactusSemi 4:1c48c9fa44fc 456 }
CactusSemi 4:1c48c9fa44fc 457 else {
CactusSemi 4:1c48c9fa44fc 458 temp = 0x00;
CactusSemi 4:1c48c9fa44fc 459 pc.printf("0");
CactusSemi 4:1c48c9fa44fc 460 }
CactusSemi 4:1c48c9fa44fc 461 temp = (temp | NVM_RESET | NVM_PWR_ON); //NVM_PWE1 if NVM_data[i]=1 & CLK1 de-asserted
CactusSemi 4:1c48c9fa44fc 462 //pc.printf("\n\n\n\n\r\ttemp = 0x%2.2X",temp);
CactusSemi 3:3e8c16b6620c 463 i2c_write_fn(&i2c,NVM_CTLR_ADR,temp);
CactusSemi 4:1c48c9fa44fc 464 //wait_us(delay2);
CactusSemi 4:1c48c9fa44fc 465 temp = (NVM_RESET | NVM_PWR_ON);
CactusSemi 3:3e8c16b6620c 466 i2c_write_fn(&i2c,NVM_CTLR_ADR,temp); //de-assert NVM_PWE1
CactusSemi 3:3e8c16b6620c 467 wait_us(delay2);
CactusSemi 4:1c48c9fa44fc 468 temp = (NVM_RESET | NVM_CLK1 | NVM_PWR_ON);
CactusSemi 3:3e8c16b6620c 469 i2c_write_fn(&i2c,NVM_CTLR_ADR,temp); //assert CLK1
CactusSemi 3:3e8c16b6620c 470 wait_us(delay2);
CactusSemi 3:3e8c16b6620c 471 }
CactusSemi 4:1c48c9fa44fc 472
CactusSemi 3:3e8c16b6620c 473 pc.printf("\n\n\n\r\t\a\033[%dm", 44);//change backround to blue
CactusSemi 4:1c48c9fa44fc 474 //pc.printf("Finished programming. Let us confirm if the NVM has been programmed correctly by reading the NVM. Proceed (y/n): ");
CactusSemi 4:1c48c9fa44fc 475 pc.printf("Finished programming. Let us confirm if the NVM has been programmed correctly by reading the NVM.");
CactusSemi 3:3e8c16b6620c 476 pc.printf("\033[%dm", 40);//change backround to black
CactusSemi 4:1c48c9fa44fc 477 pc.printf("\n\n\n\r\tReduce PROG to 4.2V & VINA to 4.2V and press 'c' to continue");
CactusSemi 4:1c48c9fa44fc 478 while ( temp!='c') {
CactusSemi 3:3e8c16b6620c 479 temp = pc.getc();
CactusSemi 4:1c48c9fa44fc 480 }
CactusSemi 4:1c48c9fa44fc 481 i2c_write_fn(&i2c,0x10,0x00); //tm_ProgSamp_en = 0,
CactusSemi 4:1c48c9fa44fc 482 wait_ms(1);
CactusSemi 4:1c48c9fa44fc 483 //temp = 0;
CactusSemi 4:1c48c9fa44fc 484 //while ( temp!='y' ) {
CactusSemi 4:1c48c9fa44fc 485 // temp = pc.getc();
CactusSemi 4:1c48c9fa44fc 486 //}
CactusSemi 3:3e8c16b6620c 487 NVM_read_data = EasyFuse_read(&i2c);
CactusSemi 3:3e8c16b6620c 488 if ( NVM_data == NVM_read_data ) pc.printf("\n\n\r\tData written into NVM matches data read from NVM\n\n\n\r\t\033[%dm NVM PROGRAMMING SUCESSFULL. Hoorayyy!\a \033[%dm\n\r",44,40);
CactusSemi 3:3e8c16b6620c 489 else pc.printf("\n\n\r\tuh-oh.. Data written into NVM does not match data read from NVM\n\n\n\r\t\033[%dm NVM PROGRAMMING FAILED!\a \033[%dm\n\r",41,40);
CactusSemi 3:3e8c16b6620c 490 }