Hmm - no success so far. Maybe a post of my complete code helps in finding the error:
/////////////////////////////////////////////////////////////////////////////
// Include files
/////////////////////////////////////////////////////////////////////////////
#include <mios32.h>
#include "app.h"
/////////////////////////////////////////////////////////////////////////////
// Local definitions
/////////////////////////////////////////////////////////////////////////////
#define NUM_ENCODERS 64
/////////////////////////////////////////////////////////////////////////////
// Local variables
/////////////////////////////////////////////////////////////////////////////
u8 Sendbyte;
u8 enc_virtual_pos[NUM_ENCODERS];
/////////////////////////////////////////////////////////////////////////////
// This hook is called after startup to initialize the application
/////////////////////////////////////////////////////////////////////////////
void APP_Init(void)
{
// initialize all LEDs
MIOS32_BOARD_LED_Init(0xffffffff);
// initialize pin0 & pin1 of J5A as output with internal Pull-Up
MIOS32_BOARD_J5_PinInit(0, MIOS32_BOARD_PIN_MODE_OUTPUT_PP);
MIOS32_BOARD_J5_PinInit(1, MIOS32_BOARD_PIN_MODE_OUTPUT_PP);
MIOS32_BOARD_J5_PinInit(2, MIOS32_BOARD_PIN_MODE_OUTPUT_PP);
MIOS32_BOARD_J5_PinInit(3, MIOS32_BOARD_PIN_MODE_OUTPUT_PP);
// initialize rotary encoders of the same type (DETENTED2)
int enc=0;
//for(enc=0; enc<=NUM_ENCODERS; ++enc) {
//u8 pin_sr = enc >> 2; // each DIN SR has 4 encoders connected
//u8 pin_pos = (enc & 0x3) << 1; // Pin position of first ENC channel: either 0, 2, 4 or 6
u8 pin_sr = 1;
u8 pin_pos = 0;
mios32_enc_config_t enc_config = MIOS32_ENC_ConfigGet(enc);
enc_config.cfg.type = DETENTED2; // see mios32_enc.h for available types
enc_config.cfg.sr = pin_sr;
enc_config.cfg.pos = pin_pos;
enc_config.cfg.speed = FAST;
enc_config.cfg.speed_par = 3;
MIOS32_ENC_ConfigSet(enc, enc_config);
// reset virtual positions
enc_virtual_pos[enc] = 0;
//}
MIOS32_MIDI_SendDebugMessage("MIOS32_SPI_IO_Init(2, MIOS32_SPI_PIN_DRIVER_STRONG): %03u\n", MIOS32_SPI_IO_Init(2, MIOS32_SPI_PIN_DRIVER_STRONG));
}
/////////////////////////////////////////////////////////////////////////////
// This task is running endless in background
/////////////////////////////////////////////////////////////////////////////
void APP_Background(void)
{
// MIOS32_LCD_Initialize
MIOS32_LCD_Clear();
MIOS32_LCD_CursorSet(0, 0); // X, Y
MIOS32_LCD_PrintString("PreAmp Volume");
MIOS32_LCD_CursorSet(0, 1); // X, Y
MIOS32_LCD_PrintString(" Off 0000");
while (1)
{
}
}
/////////////////////////////////////////////////////////////////////////////
// This hook is called when a MIDI package has been received
/////////////////////////////////////////////////////////////////////////////
void APP_MIDI_NotifyPackage(mios32_midi_port_t port, mios32_midi_package_t midi_package)
{
// 1) LED an, wenn Gain (CC=52) <> 0 auf Midi-Kanal 3
if( midi_package.chn == 2 && midi_package.type == CC && midi_package.cc_number == 52 && midi_package.value != 0) {
//Kanalschalter-LED Frontseite einschalten
MIOS32_BOARD_J5_PinSet(0, 1);
//Relais durchschalten auf Pin1
MIOS32_BOARD_J5_PinSet(1, 1);
MIOS32_LCD_CursorSet(1, 1);
MIOS32_LCD_PrintString("On ");
}
// 2) LED aus, wenn Gain (CC=52) = 0 auf Midi-Kanal 3
else if( midi_package.chn == 2 && midi_package.type == CC && midi_package.cc_number == 52 && midi_package.value == 0) {
//Kanalschalter-LED Frontseite ausschalten
MIOS32_BOARD_J5_PinSet(0, 0);
//Relais unterbrechen auf Pin1
MIOS32_BOARD_J5_PinSet(1, 0);
MIOS32_LCD_CursorSet(1, 1);
MIOS32_LCD_PrintString("Off");
}
// forward USB0->UART0 and UART0->USB0
switch ( port ) {
case USB0: MIOS32_MIDI_SendPackage(UART0, midi_package); break;
case UART0: MIOS32_MIDI_SendPackage(USB0, midi_package); break;
}
}
/////////////////////////////////////////////////////////////////////////////
// This hook is called when a button has been toggled
// pin_value is 1 when button released, and 0 when button pressed
/////////////////////////////////////////////////////////////////////////////
void APP_DIN_NotifyToggle(u32 pin, u32 pin_value)
{
}
/////////////////////////////////////////////////////////////////////////////
// This hook is called before the shift register chain is scanned
/////////////////////////////////////////////////////////////////////////////
void APP_SRIO_ServicePrepare(void)
{
}
/////////////////////////////////////////////////////////////////////////////
// This hook is called after the shift register chain has been scanned
/////////////////////////////////////////////////////////////////////////////
void APP_SRIO_ServiceFinish(void)
{
}
/////////////////////////////////////////////////////////////////////////////
// This hook is called when an encoder has been moved
// incrementer is positive when encoder has been turned clockwise, else
// it is negative
/////////////////////////////////////////////////////////////////////////////
void APP_ENC_NotifyChange(u32 encoder, s32 incrementer)
{
// toggle Status LED on each AIN value change
MIOS32_BOARD_LED_Set(0x0001, ~MIOS32_BOARD_LED_Get());
// increment to virtual position and ensure that the value is in range 0..127
int value = enc_virtual_pos[encoder] + incrementer;
if( value < 0 )
value = 0;
else if( value > 127 )
value = 127;
enc_virtual_pos[encoder] = value;
// only send if value has changed
if( enc_virtual_pos[encoder] != value )
{
// store new value
enc_virtual_pos[encoder] = value;
// send event
}
MIOS32_MIDI_SendCC(UART0, Chn3, 53, value);
MIOS32_MIDI_SendCC(USB0, Chn3, 53, value);
short Sendbyte = value*2;
MIOS32_MIDI_SendDebugMessage("MIOS32_SPI_RC_PinSet to 0: %04u", MIOS32_SPI_RC_PinSet (2,1,0));
MIOS32_MIDI_SendDebugMessage("MIOS32_SPI_TransferByte R %04u: %04u", Sendbyte, MIOS32_SPI_TransferByte(2, Sendbyte));
MIOS32_MIDI_SendDebugMessage("MIOS32_SPI_TransferByte L: %04u: %04u", Sendbyte, MIOS32_SPI_TransferByte(2, Sendbyte));
MIOS32_MIDI_SendDebugMessage("MIOS32_SPI_RC_PinSet to 1: %04u", MIOS32_SPI_RC_PinSet (2,1,1));
MIOS32_LCD_CursorSet(10, 1);
MIOS32_LCD_PrintFormattedString("%04u", Sendbyte);
}
/////////////////////////////////////////////////////////////////////////////
// This hook is called when a pot has been moved
/////////////////////////////////////////////////////////////////////////////
void APP_AIN_NotifyChange(u32 pin, u32 pin_value)
{
}
These are the global compiler settings:
Processor: STM32F407VG
Family: STM32F4xx
Board: MBHP_CORE_STM32F4
LCD: universal
The encoder as well as the update on the LCD with every turn is working quite fine. But the PGA does not seem to transmit any audio…
Thanks for patience,
mwpost