Other Parts Discussed in Thread: CLOCKPRO
Hello.
I am able to read and write from the register, and I am not able to get this register to provide the desired PLL output.
I am using 16Mhz Crystal, and this is code I used to get the 32Mhz Output.
Variables I used were fout = 32Mhz, Fvco = 64MHz, P=2 n'' = 4*2^2 = 16 Q=16, R =0
while(data!=0x81) { // keep reading ID register until you read the correct value
// address = (CDCE925_SLAVE_ADDR<<1) & (0b11111110);//read=1 write =0 first send the write and read
aTxBuffer[0] = 0x00>>1 | 0b10000000;
// aTxBuffer[1] = 0x04;
uint16_t size = 1;
HAL_I2C_Master_Transmit(&hi2c1, (uint16_t)CDCE925_SLAVE_ADDR<<1, (uint8_t*)aTxBuffer, size, 10000);
// HAL_StatusTypeDef status = HAL_I2C_Master_Transmit(&hi2c1, (uint16_t)address, (uint8_t*)aTxBuffer, size, 10000);
// if (status != HAL_OK) {
// __NOP();
// }
address = (CDCE925_SLAVE_ADDR<<1) | (0b00000001);//read
//address = (CDCE925_SLAVE_ADDR<<1) & (0b11111110);
// aTxBuffer[0] = 0x00;
// aTxBuffer[1] = (CDCE925_SLAVE_ADDR<<1) | (0b00000001);
HAL_I2C_Master_Receive(&hi2c1,(uint8_t)address,(uint8_t*)&data, 1, 10000);
HAL_Delay(1);
// HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);
//put read the data from the device and put it there to get out of the loop
}
uint8_t data2 = 0;
uint8_t data3 = 0;
aTxBuffer[0] = 0x01;// offset
aTxBuffer[1] = 0b01000000;//writing number
PLL_I2C_write(aTxBuffer[0],aTxBuffer[1]);
HAL_Delay(10);
data2 = PLL_I2C_read(aTxBuffer[0]);
aTxBuffer[0] = 0x02;
aTxBuffer[1] = 0b10110100;//setting to crystal
PLL_I2C_write(aTxBuffer[0],aTxBuffer[1]);
HAL_Delay(10);
uint8_t data1 = 0;
while(data1 != 0b10110100){
data1 = PLL_I2C_read(aTxBuffer[0]);
}
aTxBuffer[0] = 0x03;
aTxBuffer[1] = 0b0000010;
PLL_I2C_write(aTxBuffer[0],aTxBuffer[1]);
HAL_Delay(10);
data2 = PLL_I2C_read(aTxBuffer[0]);
aTxBuffer[0] = 0x04;
aTxBuffer[1] = 0b10000000;
PLL_I2C_write(aTxBuffer[0],aTxBuffer[1]);
HAL_Delay(10);
aTxBuffer[0] = 0x05;
aTxBuffer[1] = 0b01000000;
PLL_I2C_write(aTxBuffer[0],aTxBuffer[1]);
HAL_Delay(10);
while(data1 != 0b01000000){
data1 = PLL_I2C_read(aTxBuffer[0]);
}
aTxBuffer[0] = 0x06;
aTxBuffer[1] = 0b01100001;
PLL_I2C_write(aTxBuffer[0],aTxBuffer[1]);
HAL_Delay(10);
data2 = PLL_I2C_read(aTxBuffer[0]);
data3 = PLL_I2C_read(0x01);
uint8_t data13 =0;
aTxBuffer[0] = 0x13;
aTxBuffer[1] = 0b00000000;
PLL_I2C_write(aTxBuffer[0],aTxBuffer[1]);
HAL_Delay(10);
data13 = PLL_I2C_read(0x13);
aTxBuffer[0] = 0x14;
aTxBuffer[1] = 0b01001101;
PLL_I2C_write(aTxBuffer[0],aTxBuffer[1]);
HAL_Delay(10);
while(data1 != 0b01001101){
data1 = PLL_I2C_read(0x14);
}
aTxBuffer[0] = 0x15;
aTxBuffer[1] = 0b00000000;
PLL_I2C_write(aTxBuffer[0],aTxBuffer[1]);
HAL_Delay(10);
aTxBuffer[0] = 0x16;
aTxBuffer[1] = 0b00000100;
PLL_I2C_write(aTxBuffer[0],aTxBuffer[1]);
HAL_Delay(10);
aTxBuffer[0] = 0x17;
aTxBuffer[1] = 0b00000100;
PLL_I2C_write(aTxBuffer[0],aTxBuffer[1]);
HAL_Delay(10);
aTxBuffer[0] = 0x18;
aTxBuffer[1] = 0b00000000;
PLL_I2C_write(aTxBuffer[0],aTxBuffer[1]);
HAL_Delay(10);
aTxBuffer[0] = 0x19;
aTxBuffer[1] = 0b00100000;
PLL_I2C_write(aTxBuffer[0],aTxBuffer[1]);
HAL_Delay(10);
aTxBuffer[0] = 0x1A;
aTxBuffer[1] = 0b00000010;
PLL_I2C_write(aTxBuffer[0],aTxBuffer[1]);
HAL_Delay(10);
aTxBuffer[0] = 0x1B;
aTxBuffer[1] = 0b00001000;
PLL_I2C_write(aTxBuffer[0],aTxBuffer[1]);
HAL_Delay(10);
uint8_t PLL_I2C_read(uint8_t regr) {
uint8_t address;
uint8_t data;
uint8_t aTxBuffer[4] = {0};
aTxBuffer[0] = regr | 0b10000000;
address = (CDCE925_SLAVE_ADDR<<1);
HAL_I2C_Master_Transmit(&hi2c1, (uint8_t)address, (uint8_t*)aTxBuffer, 1, 10000);
address = (CDCE925_SLAVE_ADDR<<1) | 0x01;
HAL_I2C_Master_Receive(&hi2c1,(uint8_t)address,(uint8_t*)&data, 1, 10000);
HAL_Delay(1);
return data;
}
void PLL_I2C_write(uint8_t regr, uint8_t data) {
uint8_t address;
uint8_t aTxBuffer[2];
address = (CDCE925_SLAVE_ADDR<<1);
aTxBuffer[0] = regr | 0b10000000;
//here may the error command
aTxBuffer[1] = data;
HAL_I2C_Master_Transmit(&hi2c1, (uint8_t)address, (uint8_t*)aTxBuffer, 2, 10000);
}
Any help would be greatly appreciated thank you very much