Please Post Code & Details In Your Question!

Status
Not open for further replies.

Paul

Administrator
Staff member
Please, when asking a technical question, provide enough information for us to help!


  • Complete Source Code (or a link to the code)
  • Screenshot or the exact text of any error messages
  • Which PJRC product you're using
  • Part numbers of any other chips or modules + links to their info
  • Wiring details - how exactly have you connected the hardware (a photo's worth 1000 words)
  • Software setup, Arduino vs C+makefile, running on Windows, Mac or Linux?Versions?
  • Any other information needed to reproduce the problem.....

Providing enough detailed information to reproduce your problem saves everyone time and greatly increases the odds we'll be able to help you with a useful answer.

If you haven't connected wires or run code yet, please post your question in the Project Guidance forum.
 
is there a way -tags or otherwise - to format attached code? If I copy and paste code in it is wrapping long lines and removing indention.
 
use the [ CODE] and [ /CODE] tags for that.
If you want to see all tags, click on the 'Go Advanced' button below the Quick Reply field :)
 
Unfortunately the forum software hides the button that inserts code tags, unless you click 'Advanced'. Its the button that looks like this: #

codetags.png
 
You can also attach the file. Click "go advanced" and then it's Manage Attachments below your message. Often when looking at someone's, I load it into vim, so I get familiar syntax highlighting. But the code tags work nicely for small bits of code.
 
Last edited:
When I try to run the movie2serial program, it could not load the file. Im not sure if the path I wrote is in the correct format. The fp.avi and the movie2serial is in the same folder already.
I've try both of this but none of them work.

Movie myMovie = new Movie(this, "/tmp/fp.avi");
Movie myMovie = new Movie(this, "fp.avi");
 
I'd suggest that the DMA chaining scheme could interleave the bytes: 1st pass does half, second pass does others. But DMA hardware requires address aligned buffers.
 
I am trying to merge two Audio Workshop tutorial sketches together to run the part 3-2 FFT1024 with the part 3-3 Add a TFT Display. I have a breadboard large enough to incorporate the (2.8 in ILI9341 display), audio board and Teensy 3.2 board. Of course, both tutorial sketches work fine by themselves. So I have attached the combined sketches as one file inwhich I commented out the bar drawing in 3-3 as I was just trying to print one of the FFT numbers (leftNumber) to start with instead of the peak1 or peak2 functions. The sketch compiles except at the end it gives the following error (region 'FLASH' overflow by 3768 bytes):

Error Capture Part_3_02_Rourier_Transform_Mod FLASH overflow.jpg

Not sure how to attach/upload the sketch as I am new to this forum, but here is the section I have imported from the 3-3 sketch into the bottom of the FFT sketch along with inserting the necessary TFT setup and include statements in the top part. Is it possible to print to the display as well as the serial port? I have reduced the variable "n" to an integer for the leftNumber, but somehow it is creating a FLASH overflow?

int leftNumber = (int)n; // Change leftNumber to integer of n

if (msecs > 15) {
// if (n.available() {
msecs = 0;
delay(10); // wait for library to parse WAV inf - is this necessary
// float rightNumber = n;
Serial.print(leftNumber);
Serial.print(", ");
// Serial.print(rightNumber);
// Serial.println();

// draw the verticle bars
// int height = n * 240;
// tft.fillRect(60, 280 - height, 40, height, ILI9341_GREEN);
// tft.fillRect(60, 280 - 240, 40, 240 - height, ILI9341_BLACK);
// height = n * 240;
// tft.fillRect(140, 280 - height, 40, height, ILI9341_GREEN);
// tft.fillRect(140, 280 - 240, 40, 240 - height, ILI9341_BLACK);
// a smarter approach would redraw only the changed portion...

// draw numbers underneath each bar
tft.setFont(Arial_14);
tft.fillRect(60, 284, 40, 16, ILI9341_BLACK);
tft.setCursor(60, 284);
tft.print(leftNumber);
// tft.fillRect(140, 284, 40, 16, ILI9341_BLACK);
// tft.setCursor(140, 284);
// tft.print(rightNumber);
}
// }
}
 
Last edited:
The sketch compiles except at the end it gives the following error (region 'FLASH' overflow by 3768 bytes):

This means your program is too large to fit into Teensy's flash memory.

The FFT code uses large lookup tables that consume a lot of flash memory. If you're using the example which plays a guitar sound (can't see all of your code... you didn't follow the Forum Rule... so I'm trying to help with blind guessing), that data for the guitar also consumes a lot of memory. The fonts for the display are also large, if you use any of the larger sizes (again, can only see Arial_14, hard to know if you've got any others).

You need to trim some stuff from your program so it'll fit into Teensy's memory. Especially if you have that guitar sound in your code, deleting that should free up plenty of space.
 
Everything is in the data sheets which you can download from the prjc.com website. Attention: The Teensy 3.1 is discontinued in favor of the more robust 3.2
 
@Paul, @Robin - This thread has been spammed a few times.

Wonder if it would make sense, to edit this thread, and maybe remove most everything except the first posting, where you might merge in a few of the details from other postings, like use the # button to get the code tags, which is now also available on the quick reply....

And then lock it.
 
I vote for bumping this thread all the time, it might help people read it eventually since the static red text is ignored lol :)
 
Hi! I have written a code in Keil and am using Teensy 3.2 and its audio shield. I am experiencing some issues with regards of getting an acknowledgement signal from the audio shield. Any help would be appreciated. Here is the source code

Code:
#include <MK20D7.h>
#include "kinetis.h"

#define SET(x,b) x|=(1UL<<b)
#define CLR(x,b) x=x&(~(1UL<<b))
#define CHK(x,b) (x&(1UL<<b))
#define TOG(x,b) x^=(1UL<<b)
uint16_t ana_ctrl;
uint8_t address = 0x0A;
uint8_t A = 0, A1 = 0x14 ;


#define SGTL5000_I2C_ADDR_CS_LOW    0x0A // CTRL_ADR0_CS pin low (normal configuration)
#define SGTL5000_I2C_ADDR_CS_HIGH    0x2A // CTRL_ADR0_CS pin high

void I2C_Write(int x) ;
void I2C_Read( int y);

volatile uint32_t msTicks; /* counts 1ms timeTicks */


/*----------------------------------------------------------------------------
  SysTick_Handler
  ----------------------------------------------------------------------------*/
void SysTick_Handler(void) {
  msTicks++; //increment counter necessary in Delay()//
}


/*------------------------------------------------------------------------------
  delays number of tick Systicks (happens every 1 ms)
  ------------------------------------------------------------------------------*/


__INLINE static void Delay (uint32_t dlyTicks) {
  uint32_t curTicks;

  curTicks = msTicks;
  while ((msTicks - curTicks) < dlyTicks);
}


void delay_us(int xyz)
{
  uint16_t MN = 18 * xyz;
  for (int mn = 0; mn <= MN; mn++)
  {
  }
}

long a = 1 , b = 0, c = 0, d = 0;

/*---------------------------LED Configuration------------------------------------*/
void Led_Config(void)
{
  SIM -> SCGC5 |= (1UL << 11);
  PORTC -> PCR[5] |= (1UL << 8);
  PORTC -> PCR[5] |= (1UL << 6);
  PTC -> PDDR |= (1UL << 5);
  PTC -> PDOR |= 0;
}

void Led_On()
{
  PTC -> PDOR |= (1UL << 5);
}


void Led_Off()
{
  PTC -> PDOR = 0;

}


/*----------------------------I2C COnfiguration---------------------------------------*/
void I2C_config(void)
{
  SIM -> SCGC4 |= (1UL << 6);
  SIM -> SCGC5 |= (1UL << 10);

  PORTB -> PCR[2] |= (1UL << 9); //SCL Initalize//
  PORTB -> PCR[3] |= (1UL << 9); //SDA Initalize//

  SET(PORTB -> PCR[2], 1);
  SET(PORTB->PCR[3], 1); //Pullup enable//

  SET(PORTB -> PCR[2], 0); //Pull select//
  SET(PORTB->PCR[3], 0);

  SET(PORTB -> PCR[2], 2); //Slew Rate Enable//
  SET(PORTB->PCR[3], 2);

  SET(PORTB -> PCR[2], 6); //Drive Strength Enable//
  SET(PORTB->PCR[3], 6);

  SET(PORTB -> PCR[2], 5); //Open Drain Enable//
  SET(PORTB->PCR[3], 5);

  SET(PORTB->PCR[3], 16); //IRQC at rising edge in SDA//
  SET(PORTB->PCR[3], 19);

  SET(PORTB->PCR[3], 24);
  I2C0_F = 0X13;

}

/*----------------------I2S config-------------------------------*/
void I2S_Config()
{
  SET(SIM_SCGC6, 15);
  SET(SIM_SCGC5, 11);
  SET(PORTC->PCR[6], 10);
  SET(PORTC->PCR[6], 9);

  SET(PORTC->PCR[6], 1);
  SET(PORTC->PCR[6], 5);
  SET(PORTC->PCR[6], 6);

  I2S0_MCR |= 0x40000000;
  I2S0_MDR |= 0x0006327C;
}
/*------------------------------------------Start and Stop Signals-------------------------------------------*/
void StartConfig()
{
  SET(PTB -> PDOR, 2);//SCL HIGH//
  SET(PTB -> PDOR, 3); //SDA HIGH//
  delay_us(100);
  CLR(PTB -> PDOR , 3); //SDA LOW//
}

void StopConfig()
{
  CLR(PTB -> PDOR, 3); //SDA LOW//
  delay_us(100);
  SET(PTB -> PDOR, 3); //SDA HIGH//
  CLR(PTB -> PDOR, 2);//SCL LOW//
}


void ack()
{
  while (CHK(PTB -> PDOR, 3));
}

void I2C_Write(x)
{
  I2C0_D = x;
  ack();

  Delay(10);
  while (!CHK(I2C0_S, 1));
  while ((CHK(I2C0_S, 0)));
  SET(I2C0_S, 1);

}


void I2C_Read(y)
{
  y = I2C0_D;
}

void Master_Write( uint8_t data)
{

  SET(I2C0_S, 1);
  SET(I2C0_S, 4);

  I2C0_C1 = 0 ;

  SET(I2C0_C1, 6);
  SET(I2C0_C1, 7);
  SET(I2C0_C1, 4);
  SET(I2C0_C1, 5);

  StartConfig();

  if (CHK(I2C0_C1, 5))
  {


    I2C0_C1 = 0xF4 ;

    Delay(5);

    if (CHK(I2C0_S, 5))

    {

      I2C_Write(A1);
      I2C_Write(CHIP_ANA_POWER >> 8);
      I2C_Write(CHIP_ANA_POWER);
    }

    else
    {

    }

  }

}



void write(unsigned int reg, unsigned int val)
{
  StartConfig();
  SET(I2C0_C1, 5);

  Master_Write(reg >> 8);
  Master_Write(reg);
  Master_Write(val >> 8);
  Master_Write(val);

  CLR(I2C0_C1, 5);

  StopConfig();

  Led_On();
  Delay(200);
  Led_Off();
  Delay(100);
}





/*----------------------------------------------Main Program Start-----------------------------------------*/
int main(void)
{
  uint16_t ana_ctrl;
  SystemCoreClockUpdate(); /* Get Core Clock Frequency */
  SysTick_Config(SystemCoreClock / 1000); /* Generate interrupt each 1 ms */
  Delay(500);

  Led_Config();
  I2C_config();
  I2S_Config();

  Master_Write(0x20);

  while (1)
  {

  }
}


void SGTL_enable()
{


  Delay(5);

  write(CHIP_ANA_POWER, 0x4060); // VDDD is externally driven with 1.8V
  write(CHIP_LINREG_CTRL, 0x006C); // VDDA & VDDIO both over 3.1V
  write(CHIP_REF_CTRL, 0x01F2); // VAG=1.575, normal ramp, +12.5% bias current
  write(CHIP_LINE_OUT_CTRL, 0x0F22); // LO_VAGCNTRL=1.65V, OUT_CURRENT=0.54mA
  write(CHIP_SHORT_CTRL, 0x4446); // allow up to 125mA
  write(CHIP_ANA_CTRL, 0x0137); // enable zero cross detectors
  write(CHIP_ANA_POWER, 0x40BF); // power up: lineout, hp, adc, dac
  write(CHIP_DIG_POWER, 0x0073); // power up all digital stuff
  Delay(400);
  write(CHIP_LINE_OUT_VOL, 0x1D1D); // default approx 1.3 volts peak-to-peak
  write(CHIP_CLK_CTRL, 0x0004); // 44.1 kHz, 256*Fs
  write(CHIP_I2S_CTRL, 0x0130); // SCLK=32*Fs, 16bit, I2S format
  // default signal routing is ok?
  write(CHIP_SSS_CTRL, 0x0000); // ADC->I2S, I2S->DAC
  write(CHIP_ADCDAC_CTRL, 0x0000); // disable dac mute
  write(CHIP_DAC_VOL, 0x3C3C); // digital gain, 0dB
  write(CHIP_ANA_HP_CTRL, 0x0000); // set volume (lowest level)
  write(CHIP_ANA_CTRL, 0x0122); // enable zero cross detectors

}
 
Last edited by a moderator:
Easy enough. Edited the post.

@Defragster, KurtE & other "plus" users... please feel free to add code tags if you see these messages. Just add a quick note in the reason for editing field.
 
I am experiencing some issues with regards of getting an acknowledgement signal from the audio shield. Any help would be appreciated.

Looks like you're implementing I2C with bit bashing the GPIO registers. You probably need to add many more software delays, since the chip is much faster than the rise times of those signals. For example, I see busy loops that wait for the low->high transition and then the instant that slowly rising voltage hits the logic threshold, you do stuff on other pins without any extra delay to allow the signal to keep rising well into the logic high noise margin. That sort of thing might work, but on chips this fast you probably need more delays.

Or you could try using the Wire or i2c_t3 libraries for the I2C hardware. Even if you never intend to run Arduino, you could use the code as a guide to get I2C working reliably (if Keil doesn't provide anything that works?)

https://github.com/PaulStoffregen/Wire/blob/master/WireKinetis.cpp

If you don't go with working I2C code, maybe get a cheap logic analyzer or scope with protocol analysis to view the waveforms. That'll almost certainly show where you're not implementing I2C correctly.
 
I tried what you suggested but the issue hasn't been solved yet. Is there any other way to get this done? I also checked the cpp file you mentioned and found that I have been doing mostly the same things that you have done there.
 
I tried what you suggested but the issue hasn't been solved yet. Is there any other way to get this done? I also checked the cpp file you mentioned and found that I have been doing mostly the same things that you have done there.
Not sure what you are saying here? Did you try by using the Wire library or i2c_t3? Also mostly doing the same things?

Also might help to know what the issues are... You are not getting the signals? At all? Or only in some specific cases?

P.S. - Wish this was on it's own thread instead of this global sticky thread...
 
I ran into some problems when I connected the Teensy to a DSO. There was no SCL clock signal generated. Can someone take a look at my I2C initialization and start and stop signal codes and point out any problems with it? Thanks.



Hi! I have written a code in Keil and am using Teensy 3.2 and its audio shield. I am experiencing some issues with regards of getting an acknowledgement signal from the audio shield. Any help would be appreciated. Here is the source code

Code:
#include <MK20D7.h>
#include "kinetis.h"

#define SET(x,b) x|=(1UL<<b)
#define CLR(x,b) x=x&(~(1UL<<b))
#define CHK(x,b) (x&(1UL<<b))
#define TOG(x,b) x^=(1UL<<b)
uint16_t ana_ctrl;
uint8_t address = 0x0A;
uint8_t A = 0, A1 = 0x14 ;


#define SGTL5000_I2C_ADDR_CS_LOW    0x0A // CTRL_ADR0_CS pin low (normal configuration)
#define SGTL5000_I2C_ADDR_CS_HIGH    0x2A // CTRL_ADR0_CS pin high

void I2C_Write(int x) ;
void I2C_Read( int y);

volatile uint32_t msTicks; /* counts 1ms timeTicks */


/*----------------------------------------------------------------------------
  SysTick_Handler
  ----------------------------------------------------------------------------*/
void SysTick_Handler(void) {
  msTicks++; //increment counter necessary in Delay()//
}


/*------------------------------------------------------------------------------
  delays number of tick Systicks (happens every 1 ms)
  ------------------------------------------------------------------------------*/


__INLINE static void Delay (uint32_t dlyTicks) {
  uint32_t curTicks;

  curTicks = msTicks;
  while ((msTicks - curTicks) < dlyTicks);
}


void delay_us(int xyz)
{
  uint16_t MN = 18 * xyz;
  for (int mn = 0; mn <= MN; mn++)
  {
  }
}

long a = 1 , b = 0, c = 0, d = 0;

/*---------------------------LED Configuration------------------------------------*/
void Led_Config(void)
{
  SIM -> SCGC5 |= (1UL << 11);
  PORTC -> PCR[5] |= (1UL << 8);
  PORTC -> PCR[5] |= (1UL << 6);
  PTC -> PDDR |= (1UL << 5);
  PTC -> PDOR |= 0;
}

void Led_On()
{
  PTC -> PDOR |= (1UL << 5);
}


void Led_Off()
{
  PTC -> PDOR = 0;

}


/*----------------------------I2C COnfiguration---------------------------------------*/
void I2C_config(void)
{
  SIM -> SCGC4 |= (1UL << 6);
  SIM -> SCGC5 |= (1UL << 10);

  PORTB -> PCR[2] |= (1UL << 9); //SCL Initalize//
  PORTB -> PCR[3] |= (1UL << 9); //SDA Initalize//

  SET(PORTB -> PCR[2], 1);
  SET(PORTB->PCR[3], 1); //Pullup enable//

  SET(PORTB -> PCR[2], 0); //Pull select//
  SET(PORTB->PCR[3], 0);

  SET(PORTB -> PCR[2], 2); //Slew Rate Enable//
  SET(PORTB->PCR[3], 2);

  SET(PORTB -> PCR[2], 6); //Drive Strength Enable//
  SET(PORTB->PCR[3], 6);

  SET(PORTB -> PCR[2], 5); //Open Drain Enable//
  SET(PORTB->PCR[3], 5);

  SET(PORTB->PCR[3], 16); //IRQC at rising edge in SDA//
  SET(PORTB->PCR[3], 19);

  SET(PORTB->PCR[3], 24);
  I2C0_F = 0X13;

}

/*----------------------I2S config-------------------------------*/
void I2S_Config()
{
  SET(SIM_SCGC6, 15);
  SET(SIM_SCGC5, 11);
  SET(PORTC->PCR[6], 10);
  SET(PORTC->PCR[6], 9);

  SET(PORTC->PCR[6], 1);
  SET(PORTC->PCR[6], 5);
  SET(PORTC->PCR[6], 6);

  I2S0_MCR |= 0x40000000;
  I2S0_MDR |= 0x0006327C;
}
/*------------------------------------------Start and Stop Signals-------------------------------------------*/
void StartConfig()
{
  SET(PTB -> PDOR, 2);//SCL HIGH//
  SET(PTB -> PDOR, 3); //SDA HIGH//
  delay_us(100);
  CLR(PTB -> PDOR , 3); //SDA LOW//
}

void StopConfig()
{
  CLR(PTB -> PDOR, 3); //SDA LOW//
  delay_us(100);
  SET(PTB -> PDOR, 3); //SDA HIGH//
  CLR(PTB -> PDOR, 2);//SCL LOW//
}


void ack()
{
  while (CHK(PTB -> PDOR, 3));
}

void I2C_Write(x)
{
  I2C0_D = x;
  ack();

  Delay(10);
  while (!CHK(I2C0_S, 1));
  while ((CHK(I2C0_S, 0)));
  SET(I2C0_S, 1);

}


void I2C_Read(y)
{
  y = I2C0_D;
}

void Master_Write( uint8_t data)
{

  SET(I2C0_S, 1);
  SET(I2C0_S, 4);

  I2C0_C1 = 0 ;

  SET(I2C0_C1, 6);
  SET(I2C0_C1, 7);
  SET(I2C0_C1, 4);
  SET(I2C0_C1, 5);

  StartConfig();

  if (CHK(I2C0_C1, 5))
  {


    I2C0_C1 = 0xF4 ;

    Delay(5);

    if (CHK(I2C0_S, 5))

    {

      I2C_Write(A1);
      I2C_Write(CHIP_ANA_POWER >> 8);
      I2C_Write(CHIP_ANA_POWER);
    }

    else
    {

    }

  }

}



void write(unsigned int reg, unsigned int val)
{
  StartConfig();
  SET(I2C0_C1, 5);

  Master_Write(reg >> 8);
  Master_Write(reg);
  Master_Write(val >> 8);
  Master_Write(val);

  CLR(I2C0_C1, 5);

  StopConfig();

  Led_On();
  Delay(200);
  Led_Off();
  Delay(100);
}





/*----------------------------------------------Main Program Start-----------------------------------------*/
int main(void)
{
  uint16_t ana_ctrl;
  SystemCoreClockUpdate(); /* Get Core Clock Frequency */
  SysTick_Config(SystemCoreClock / 1000); /* Generate interrupt each 1 ms */
  Delay(500);

  Led_Config();
  I2C_config();
  I2S_Config();

  Master_Write(0x20);

  while (1)
  {

  }
}


void SGTL_enable()
{


  Delay(5);

  write(CHIP_ANA_POWER, 0x4060); // VDDD is externally driven with 1.8V
  write(CHIP_LINREG_CTRL, 0x006C); // VDDA & VDDIO both over 3.1V
  write(CHIP_REF_CTRL, 0x01F2); // VAG=1.575, normal ramp, +12.5% bias current
  write(CHIP_LINE_OUT_CTRL, 0x0F22); // LO_VAGCNTRL=1.65V, OUT_CURRENT=0.54mA
  write(CHIP_SHORT_CTRL, 0x4446); // allow up to 125mA
  write(CHIP_ANA_CTRL, 0x0137); // enable zero cross detectors
  write(CHIP_ANA_POWER, 0x40BF); // power up: lineout, hp, adc, dac
  write(CHIP_DIG_POWER, 0x0073); // power up all digital stuff
  Delay(400);
  write(CHIP_LINE_OUT_VOL, 0x1D1D); // default approx 1.3 volts peak-to-peak
  write(CHIP_CLK_CTRL, 0x0004); // 44.1 kHz, 256*Fs
  write(CHIP_I2S_CTRL, 0x0130); // SCLK=32*Fs, 16bit, I2S format
  // default signal routing is ok?
  write(CHIP_SSS_CTRL, 0x0000); // ADC->I2S, I2S->DAC
  write(CHIP_ADCDAC_CTRL, 0x0000); // disable dac mute
  write(CHIP_DAC_VOL, 0x3C3C); // digital gain, 0dB
  write(CHIP_ANA_HP_CTRL, 0x0000); // set volume (lowest level)
  write(CHIP_ANA_CTRL, 0x0122); // enable zero cross detectors

}
 
I have a teensy 3.2 and the Octo 2811 hooked up to my visual pinball system. I have a two screen layout. As soon as I connect the teensy to the USB port and I try to run a game on pinball x the b-2s screen opens up but any machine that uses the DMD,for example theater of magic or Addams family, DMD does not come up. Once I disconnect the teensy from the USB port and I restart the tables the DMD shows up again. Any other table that does not have DMD open up fine and the b2s work as it should. What could be the problem. Do you have any suggestions.
 
Status
Not open for further replies.
Back
Top