Browse Source

Fixed twi address

Tested code to write si5153 registers
wspr-beacon
Sebastian 2 years ago
parent
commit
546a9c7fde
3 changed files with 29 additions and 6 deletions
  1. +20
    -0
      firmware/include/si5351.h
  2. +8
    -5
      firmware/main.c
  3. +1
    -1
      firmware/twi.c

+ 20
- 0
firmware/include/si5351.h View File

@ -0,0 +1,20 @@
#ifndef __SI5351_H__
#define __SI5351_H__ __SI5351_H__
#include <stdint.h>
#include "twi.h"
const uint8_t SI5351_ADDRESS = 96;
static inline uint8_t si5351_write8(uint8_t reg, uint8_t value) {
uint8_t data[3] = {reg, value};
return twi_write(SI5351_ADDRESS, data, 2);
}
static inline uint8_t si5351_write16(uint8_t reg, uint16_t value) {
uint8_t data[3] = {reg, value & 0xFF, (value & 0xFF00) >> 8};
return twi_write(SI5351_ADDRESS, data, 3);
}
#endif

+ 8
- 5
firmware/main.c View File

@ -2,16 +2,19 @@
#include <util/delay.h>
#include "twi.h"
#include "si5351.h"
int main(void) {
twi_init();
while(1) {
uint8_t data[] = {'T','E','S','T'};
twi_write(96, data, 4);
_delay_ms(10);
}
// Disable outputs
si5351_write8(3, 0xFF);
// Powerdown output drivers
si5351_write8(16, 0x80);
si5351_write8(17, 0x80);
si5351_write8(18, 0x80);
while(1);
}

+ 1
- 1
firmware/twi.c View File

@ -35,7 +35,7 @@ uint8_t twi_write(uint8_t address, uint8_t data[], uint8_t len) {
return 1;
}
TWDR = address | TW_WRITE; // We want to write to the slave
TWDR = (address << 1) | TW_WRITE; // We want to write to the slave
TWCR = (1 << TWINT) | (1 << TWEN); // Trigger transmission, keep TWI enabled
// Wait for TWI unit to finish


Loading…
Cancel
Save