Jump to content
Sign in to follow this  
jtvalley

MSP432 transferring audio data to DAC through XBee

Recommended Posts

Hello!

 

I am having trouble getting the correct values from my MSP432 to my DAC. So basically my project setup is as follows:

 

Transmitting:

-Microphone connected to the A15 channel of my MSP432 

-Xbee connected to the UART pins 3.2, 3.3

 

CODE Tx:

 
const int MICAN = A15;    // MIC in
 
void setup() {
Serial1.begin(9600); // baud rate setting
}
 
void loop() {
 
  Serial1.print(analogRead(MICAN));// send mic value over serial
  delay(100);   // for testing
}

///////////////////////////////////////////////////////////////////////

 

Receiving: 

-MSP432 connected to my other Xbee device UART pins 3.2, 3.3 

-MSP432 connected to LTC1658 14-bit DAC. 

    -DAC is connected to pins 1.6 (MOSI, or input), 4.3 (CS), and 1.5 (SCLK)

 

CODE Rx:

const int slaveSelectPin = 6;  // CS for the DAC
#include <SPI.h>
 
int DacVal = 0;        // value to be sent to the dac
 
void setup() {
  Serial1.begin(9600);//baud rate setting
  //spi crap
  pinMode (slaveSelectPin, OUTPUT);
  SPI.setClockDivider(SPI_CLOCK_DIV4);
  SPI.begin();
  
}
 
void loop() {
 
 if (Serial1.available()>0) {// If there is SHIT in the buffer
          DacVal = Serial1.read();
  }
  //YOUR POST PROCESING HERE!!!!!!!
  DACWrite(DacVal);
 
}
 
void DACWrite(int Val) {
 
  char LSBs;
  char MSBs;
  // take the SS pin low to select the chip:
  //Split the int to 2 chars, the bit shift may be off, but i dont have any hardware to test on
  LSBs=char(Val);
  MSBs=char(Val>>8);
  
  digitalWrite(slaveSelectPin,LOW);  
  //  send in the address and value via SPI 1 byte at a time:
  SPI.transfer(LSBs);
  SPI.transfer(MSBs);
  // take the SS pin high to de-select the chip:
  digitalWrite(slaveSelectPin,HIGH);
}

//////////////////////////////////////

 

And basically I am not getting values that are correct when I put a oscilloscope on the output of the DAC. I am thinking my problem is somewhere in the Rx code because when my Tx board is setup I am reading the values from my other zigbee through the computer successfully. Any help would be great, thank you!!

Share this post


Link to post
Share on other sites

Regarding my last post... I don't think the microphone values are correct when transmitting. I can send dummy values successfully through the xbees but I think something is wrong when I try to transmit the audio signal... 

Share this post


Link to post
Share on other sites

Can you use spi and uart? I seem to be getting the values of the mic but they don't transfer to the dac?? when I add a serial.print in the Rx code. I can see numbers popping up but only when i send a number..

Share this post


Link to post
Share on other sites

@@Fmilburn

Sorry for the confusing post... So I don't honestly know what the problem is... I am pretty sure that the transmitting part of the project is okay. I am sending data and I can see that I am through different software. However, I don't think the data is being transferred to the DAC. When I put an oscilloscope on the DAC output I get no voltage. So, I am 95% sure its with the receiving part. I don't know if my bit shift is off or if the dac is just not getting any data. I also don't really know how to troubleshoot in Energia. 

Share this post


Link to post
Share on other sites

@@jtvalley

 

You can debug Energia with Code Composer Studio (CCS).  Do a search for the words debug Energia and CCS here on 43oh and you should find a number of places where it is discussed.

 

Regarding your problem, try something like this:

#include <SPI.h>

// SPI    SCK = 7
//        MISO = 14
//        MOSI = 15
const int cs = 8;    // SPI chip select

void setup()
{
  Serial.begin(115200);
  Serial.println("Starting...");
  pinMode(cs, OUTPUT);
  SPI.begin();
}

void loop()
{
  byte lsb;
  byte msb;
  int i;
  for (i = 0; i < 512; i++)
  {
    lsb = byte(i);
    msb = byte(i >> 8);
    
    // Print the bytes to serial monitor
    Serial.print(i);
    Serial.print("   "); Serial.print(lsb, BIN);
    Serial.print("   "); Serial.println(msb, BIN);
    
    // Send the bytes out over SPI
    digitalWrite(cs, LOW);
    SPI.transfer(lsb);
    SPI.transfer(msb);
    digitalWrite(cs, HIGH);
    
    delay(10);
  }
}

I see the wiggles on the scope on pins 7, 8, 15.  I don't have anything hooked up so nothing on 14 of course.  The info is also being sent to the serial monitor.

 

This should tell you if the microcontroller is at least trying to send information to the DAC. If the DAC isn't responding to what you send it, time to look at the datasheet....

Share this post


Link to post
Share on other sites

Yes, I can also see the wiggles on the scope. This is working for the DAC. This is why I don't understand why I can't get the signal from the xbees... I will try again

Share this post


Link to post
Share on other sites

@Fmilburn
 
Okay now I am actually getting sound from the project! However, it is kinda just noise I don't think my bitshift is correct or the values are being converted correctly?

 

Code:

const int cs = 8;    // SPI chip select
int testVal;
  char DacValue;
 
void setup()
{
  Serial.begin(9600);
  Serial1.begin(9600);
  Serial.println("Starting...");
  pinMode(cs, OUTPUT);
  SPI.begin();
}
 

void loop()
{
  if (Serial1.available()) {// If there is SHIT in the buffer
    delay(1); //You may need a delay here for reliability
    DacValue = Serial1.read();
    //Serial.print(DacValue);
  }
 
    DacValue = ((DacValue-400)*2);
    char lsb = (DacValue);
    char msb = (DacValue >> 8);
    Serial.print(DacValue);
   
// Send the bytes out over SPI
    digitalWrite(cs, LOW);
    SPI.transfer(lsb);
    SPI.transfer(msb);
    digitalWrite(cs, HIGH);
    
    delay(10);
  }

Share this post


Link to post
Share on other sites

Well, it is good that you are finally getting a response from it.  My advice is to keep breaking it down into pieces that are easily understood and tested.  You are going to have to dig into the datasheets and make sure you are sending it what is expected. You can see what is going to the DAC on the serial monitor now.  Of course a logic analyzer would be handy if you  have access to one. Can you do something like generate a sine wave, read it in, and then play around with sending it to the DAC until you get the right output?

 

Regarding analogRead(), you can set the resolution with the analogResolution() function:  http://forum.43oh.com/topic/9120-how-to-set-adc14-conversion-msp432-14-bit-adc-functioning-as-10-bit/

 

How you use the returned value from analogRead() - say mapping it to values between 0 and 3.3 or whatever number you want - is up to you.

 

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×