Changeset - 851511077b87
[Not reviewed]
default
0 4 0
Ethan Zonca (ethanzonca) - 9 years ago 2017-01-03 15:13:32
e@ethanzonca.com
Fix issue where miso was never initted
4 files changed with 7 insertions and 10 deletions:
0 comments (0 inline, 0 general)
Libraries/Si446x/si446x.c
Show inline comments
 
@@ -200,100 +200,101 @@ static void delay_cycles(void)
 
		asm("NOP");
 
		delay_cycles--;
 
	}
 
}
 
 
 
// Send a command to the radio (Blocking)
 
// Avoid calling this during code runtime as it will block for a significant period of time due to delays
 
void si446x_sendcmd(uint8_t tx_len, uint8_t* data, uint8_t doack)
 
{
 
    SI446x_SELECT;
 
 
    delay_cycles();
 
 
    uint8_t dummyrx[25];
 
    if(tx_len >=25)
 
    {
 
    	SI446x_DESELECT;
 
    	return;
 
    }
 
 
    // using transmit receive to transmit data because it actually blocks until the data is sent
 
    // an additional byte is added on to the transmission so we can receive the CTS byte
 
 
    HAL_StatusTypeDef res = HAL_SPI_TransmitReceive(&hspi1, data, dummyrx, tx_len+1, SI446x_TIMEOUT);
 
    volatile HAL_StatusTypeDef res = HAL_SPI_TransmitReceive(&hspi1, data, dummyrx, tx_len+1, SI446x_TIMEOUT);
 
 
    if(res != HAL_OK)
 
    {
 
    	SI446x_DESELECT;
 
    	return;
 
    }
 
 
    SI446x_DESELECT;
 
 
    // If checking for the ACK, perform a SPI read and see if the command was acknowledged
 
    if(doack)
 
    {
 
		delay_cycles();
 
 
		SI446x_SELECT;
 
 
		int reply = 0x00;
 
		uint8_t tx_requestack[2];
 
		tx_requestack[0] = SI446x_CMD_READ_CMD_BUFF;
 
		tx_requestack[1] = 0x00;
 
 
		uint16_t attempts = 0;
 
		volatile uint16_t attempts = 0;
 
 
		// Keep trying receive until it returns 0xFF (successful ACK)
 
		while (reply != 0xFF)
 
		{
 
			// Attempt to receive two bytes from the Si446x which should be an ACK
 
			uint8_t tmprx[2] = {0,0};
 
			res = HAL_SPI_TransmitReceive(&hspi1, tx_requestack, tmprx, 2, SI446x_TIMEOUT);
 
			if(res != HAL_OK)
 
			{
 
				//error_assert_silent(ERR_VHF_SPIBUSY);
 
		    	break; // Break out, deinit, and exit
 
			}
 
			reply = tmprx[1];
 
 
			// Cycle chip select line on and off
 
			if (reply != 0xFF)
 
			{
 
				delay_cycles();
 
				SI446x_DESELECT;
 
				delay_cycles();
 
				SI446x_SELECT;
 
				delay_cycles();
 
				//HAL_GPIO_TogglePin(LED_ACT);
 
			}
 
 
			// Maximum number of attempts exceeded
 
			if(attempts > 1024)
 
			{
 
				//error_assert_silent(ERR_VHF_TIMEOUT);
 
				volatile uint32_t test = 344;
 
				break; // Break out, deinit and exit
 
			}
 
			attempts++;
 
		}
 
    }
 
 
    // Turn off activity LED
 
    //HAL_GPIO_WritePin(LED_ACT, GPIO_PIN_RESET);
 
 
    SI446x_DESELECT;
 
    delay_cycles();
 
}
 
 
 
// Set transmit frequency of Si446x
 
void si446x_setchannel(uint32_t frequency)
 
{
 
 
    // Set the output divider according to recommended ranges given in si446x datasheet
 
    uint32_t outdiv = 4;
 
    uint32_t band = 0;
 
    if (frequency < 705000000UL) { outdiv = 6;  band = 1;};
 
    if (frequency < 525000000UL) { outdiv = 8;  band = 2;};
 
    if (frequency < 353000000UL) { outdiv = 12; band = 3;};
 
@@ -357,66 +358,66 @@ void si446x_cw_off(void)
 
 
// Returns 1 if CW is on or 0 if CW is off
 
inline uint8_t si446x_tx_status(void)
 
{
 
	return si446x_cw_status;
 
}
 
 
 
// Initialize SPI port for generation of direct modulation for Si446x
 
static void __init_spi1(void)
 
{
 
 
	GPIO_InitTypeDef GPIO_InitStruct;
 
 
	// GPIO: VHF chip select
 
	GPIO_InitStruct.Pin = SI446x_CS_PIN;
 
	GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
 
	GPIO_InitStruct.Pull = GPIO_NOPULL;
 
	GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
 
	HAL_GPIO_Init(SI446x_CS_PORT, &GPIO_InitStruct);
 
	SI446x_DESELECT;
 
 
	// SPI pins
 
	__SPI1_CLK_ENABLE();
 
	GPIO_InitStruct.Pin = SI446x_SCK_PIN|SI446x_MOSI_PIN|SI446x_MOSI_PIN;
 
	GPIO_InitStruct.Pin = SI446x_SCK_PIN|SI446x_MOSI_PIN|SI446x_MISO_PIN;
 
	GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
 
	GPIO_InitStruct.Pull = GPIO_NOPULL;
 
	GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
 
	GPIO_InitStruct.Alternate = GPIO_AF0_SPI1;
 
	HAL_GPIO_Init(SI446x_SCK_PORT, &GPIO_InitStruct);
 
 
	// SPI peripheral
 
	hspi1.Instance = SPI1;
 
	hspi1.Init.Mode = SPI_MODE_MASTER;
 
 
	hspi1.Init.Direction = SPI_DIRECTION_2LINES;
 
 
	hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
 
	hspi1.Init.CLKPolarity = SPI_POLARITY_LOW; // Double-check, this is usually high, but might be low for this chip
 
	hspi1.Init.CLKPhase = SPI_PHASE_1EDGE; // was 1edge before (rising edge of clock)
 
	hspi1.Init.NSS = SPI_NSS_SOFT;
 
	hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16;
 
	hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32;
 
	hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
 
	hspi1.Init.TIMode = SPI_TIMODE_DISABLED;
 
	hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
 
	hspi1.Init.NSSPMode = SPI_NSS_PULSE_DISABLED;
 
	HAL_SPI_Init(&hspi1);
 
}
 
 
 
// Place the Si446x into shutdown
 
void si446x_shutdown(void)
 
{
 
    HAL_GPIO_WritePin(SI446x_SHUTDOWN, GPIO_PIN_SET);
 
}
 
 
 
// Wake up the Si446x from shutdown
 
void si446x_wakeup(void)
 
{
 
    HAL_GPIO_WritePin(SI446x_SHUTDOWN, GPIO_PIN_RESET);
 
}
 
 
 
// Accessor for SPI1  handle
 
SPI_HandleTypeDef* spi1_get(void)
Libraries/Si446x/si446x.h
Show inline comments
 
#ifndef SI446X_H
 
#define SI446X_H
 
 
#include "stm32f0xx_hal.h"
 
 
 
// Hardware Options ///////////////////
 
 
// Timeout for blocking writes
 
#define SI446x_TIMEOUT 10
 
#define SI446x_TIMEOUT 50
 
 
// Crystal/oscillator frequency
 
#define SI446x_VCXO_FREQ  26000000UL
 
#define SI446x_SPI SPI1
 
 
// GPIO assignments
 
#define SI446x_CS_PORT GPIOA
 
#define SI446x_CS_PIN GPIO_PIN_15
 
 
#define SI446x_GPIO_PORT GPIOA
 
#define SI446x_GPIO_PIN GPIO_PIN_10
 
 
#define SI446x_SHUTDOWN_PORT GPIOA
 
#define SI446x_SHUTDOWN_PIN GPIO_PIN_9
 
 
#define SI446x_MOSI_PORT GPIOB
 
#define SI446x_MOSI_PIN GPIO_PIN_5
 
 
#define SI446x_MISO_PORT GPIOB
 
#define SI446x_MISO_PIN GPIO_PIN_4
 
 
#define SI446x_SCK_PORT GPIOB
 
#define SI446x_SCK_PIN GPIO_PIN_3
 
Libraries/aprs/afsk.c
Show inline comments
 
@@ -254,52 +254,48 @@ void afsk_timer_stop()
 
	// Resting duty cycle
 
	// Output 0v (could be 255/2, which is 0v after coupling... doesn't really matter)
 
	//OCR2A = 0x80;
 

	
 
	// Disable playback interrupt
 
	//TIMSK2 &= ~_BV(TOIE2);
 
    //nvic_disable_irq(NVIC_TIM1_CC_IRQ);
 
//	HAL_NVIC_DisableIRQ(TIM1_CC_IRQn);
 
//	HAL_NVIC_DisableIRQ(TIM1_BRK_UP_TRG_COM_IRQn);
 
	HAL_TIM_PWM_Stop_IT(&htim1, TIM_CHANNEL_3);
 
    //timer_disable_counter(TIM1);
 
}
 

	
 

	
 
// External
 

	
 
void afsk_start(void)
 
{
 
	phasedelta = PHASE_DELTA_1200;
 
	phase = 0;
 
	packet_pos = 0;
 
	current_sample_in_baud = 0;
 
	go = 1;
 

	
 
    // Wake up and configure radio
 
    //si446x_prepare();
 
    HAL_Delay(100);
 

	
 
	// Key the radio
 
	si446x_cw_on();
 

	
 
	// Start transmission
 
	afsk_timer_start();
 
}
 

	
 
uint8_t afsk_busy(void)
 
{
 
	return go;
 
}
 

	
 
void afsk_send(const uint8_t *buffer, uint16_t len)
 
{
 
	afsk_packet_size = len;
 
	afsk_packet = buffer;
 
}
 

	
 
TIM_HandleTypeDef* afsk_timer_gethandle(void)
 
{
 
	return &htim1;
 
}
 

	
 

	
Source/main.c
Show inline comments
 
@@ -12,42 +12,42 @@
 
#include "stm32f0xx_hal.h"
 
#include "si446x/si446x.h"
 
#include "aprs/aprs.h"
 
#include "aprs/afsk.h"
 
#include "gps.h"
 
 
 
int main(void)
 
{
 
  hal_init();
 
  sysclock_init();
 
  gpio_init();
 
 
 
  afsk_init();
 
  si446x_init();
 
  gps_poweron();
 
 
  // Software timers
 
  uint32_t last_led = HAL_GetTick();
 
 
  while (1)
 
  {
 
	  // Blink LEDs
 
	  if(HAL_GetTick() - last_led > 1500)
 
	  if(HAL_GetTick() - last_led > 50)
 
	  {
 
		  gps_update_data();
 
		  aprs_send();
 
		  while(afsk_busy());
 
 
		  last_led = HAL_GetTick();
 
	  }
 
 
	  if(afsk_request_cwoff())
 
		  si446x_cw_off();
 
 
	  // High-frequency function calls
 
//	  gpio_process_shutdown();
 
//	  watchdog_feed();
 
  }
 
}
 
0 comments (0 inline, 0 general)