deleted
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Kaspars said:while (!(IFG1 & UTXIFG0));
TXBUF0 = 0x41; // WHAT IS THIS?
while (!(IFG1 & UTXIFG0));
TXBUF0 = 0x03; // WHAT IS THIS?
Kaspars,
Please see page 40 of the data sheet. TXBUF = 0x41 loads the 8-bit shift register of the transmitter. The WREG command is 010r rrrr followed by 000n nnnn so the two transmit operations above are sending WREG starting at address 1 with the intention to modify four registers in total. If you wanted to write to CH4SET (address eight) and only modify that register, you would WREG 0x48, 0x00, 0x(8-bit desired value).
OK, lets try that!
I hope that helps clarify things for you!
Kaspars,
Ports P3.5 and P3.6 do not match your code where you used P3.6 and P3.7. But I think the bigger issue is in how you use CS assignment in your code. It appears that you never actually change CS. To set low it should be '&= CS' and to set high it should be '|= ~CS'. You do not want to use '~' operator is every case.
Best regards,
Bob B
Kaspars,
For me to comment on someone else's code is really difficult, especially when it is hard to follow. I would suggest that you reformat the code with tabs or spaces to separate out the different loops so that it can be followed easier. I personally have never been a very big fan of using 'goto' commands, and with nested 'while' loops it becomes difficult to tell just what is being executed.
Let's take a look at troubleshooting. You stated earlier that START does not go high. This is key, because the START pin must be high for the converter to start converting. There are some variations to this, like pulsing the START pin, but basically the converter will not start unless the pin is high at some point. Go through the code, and see why START is not going high. There is a command to set the START pin high, but will it ever get there?
An old fashioned method of checking your code is to use highlighters or colored pencils to trace your code flow on paper. Another practice is to simplify your code into segments and test each segment for operation before combining a whole lot of code together. For example, read a register then write to it and read it again. The data should match. If it does, great. If it doesn't, you need to fix the code and get it to work correctly before moving to something else.
Overall it is better for you to search the datasheet and fully understand what is going on with the dataconverter and then be able to comment the code yourself. If you have specific questions we will be glad to help.
Best regards,
Bob B
Kaspars,
Lots of good pictures. Let's work some more on troubleshooting, and we'll look at just the first scope picture for now. The first thing is not all the plots are at the same voltage level. So DIN and DOUT are really just noise. What might be causing the noise? Maybe a bad scope ground, or maybe a bad connection from the micro. Is this a PCB layout? Or are you using a bunch of wires to connect to the EVM?
Another thing to notice is the CS. CS goes low for the first set of SCLKs and stays high for the remainder. CS must always be low when trying to communicate to the device. In other words, if you send SCLKs to the device to read or write, CS must be low.
Another thing to note is that if the first SCLK set is supposed to be a command, then DIN is not really sending any data. The problem on my end is that I have no idea what you are trying to do at this point. Nor do I know if START is high if you are trying to read data. So, what does this first scope shot supposed to be showing me?
Best regards,
Bob B
Kaspars,
The supply voltage connections you have specified is acceptable.
For the software command you are writing 0x03 to the TXBUF0 buffer. This buffer is specified in the header file for the MSP430 device. For the MSP430F1611, this would relate to the '0' peripheral (SIMO0-pin 30).
So for the 'while' you are waiting for anything that may still be in the TX buffer to clear before assigning something new to the buffer. When you assign a value to the TX buffer, the value will be clocked out of the peripheral.
Best regards,
Bob B
Kaspars,
Great job of showing your setup! You must have cleaned up a lot of your noise issues as the scope shots appear much cleaner. It also appears that you now have data coming out of the micro.
As far as the code is concerned, as I've mentioned before it is always difficult to follow someone else's code and interpret what is trying to be done. It appears to me that perhaps someone is reading data and then transmitting data out the UART (perhaps to a Serial-to-USB converter that can be written/read by a PC.) Is this what you are trying to do? It would appear so from the PS in your previous post (at least the write to PC part.)
The variable 'rx_on' appears to be a sort of flag set by the UART communication. The program will sit in the while loop until a character has been received by the UART. The received character is 'rx_data' and the program will jump back to the initial while loop and set 'rx_on' back to zero unless the received character is 0xFF (Start command). The program then reads the data and then transmits the data out the UART serial port.
My problem with this scenario is that it keeps changing the peripheral port '0' from SPI to UART modes and then back again. I would have assigned my ports differently so that I could have used the '0' peripheral for SPI and the '1' peripheral for the UART. Perhaps the original MSP430 used by the code author only had one peripheral.
So the reason the single step fails is 'rx_on' never goes to something other than '0' and the single step keeps trying to evaluate it and cannot execute the step. If you don't want to use the PC to start the program, then you need to eliminate the parts of the code that deal with the UART receive. The following code may work to start reading the data (note I commented out the lines I believe are related to receive UART start command):
while(1)
{
// while(rx_on==0); // What is this? Why I need this? And what it do?
// rx_on = 0; // What is this? Why I need this? And what it do?
// if(rx_data==0xff) goto NOSTOP; // What is this? Why I need this? And what it do?
// goto STOP_AD; // What is this? Why I need this? And what it do?
// NOSTOP:
configure_spi(); // Setup SPI
P2OUT &= ~CS_0; // SET CS "low"
P3OUT |= START; // SET START "high"
while (!(IFG1 & UTXIFG0)); // RDATAC (Read Data Continuosly)
TXBUF0 = 0x10;
while (!(IFG1 & UTXIFG0));
TXBUF0 = 0x00; // What is this? Why I need this? And what it do? I have no idea why this is done, but it should not hurt anything as it is a NOP
while (!(IFG1 & UTXIFG0));
P2OUT |= ~CS_0; // SET CS "high" conversation ends
while(1)
{
P2OUT &= CS_0; // Set CS "low"
while((P2IN & 0x02)); // What is this? Why I need this? And what it do? Important This is waiting for P2.2 to go low...perhaps this port pin was assigned to DRDY at some point by the author of the code
for (i = 0; i < 3; i++) // Read Status register // What is this? What it do? This for loop reads three bytes of STATUS data....read is initiated when the NOP is transmitted
{
while (!(IFG1 & UTXIFG0));
TXBUF0 = 0x00; // What is this? Why I need this? And what it do? This initiates the SCLK
while (!(IFG1 & URXIFG0));
STAT0[i] = RXBUF0; // What is this? Why I need this? And what it do? sending? STAT0 is a 3 character array, and the SPI RX buffer is stored to the array
}
for (i = 0; i < 24; i++) // Read Channel data // What is this? And what it do? This loop reads 24 bytes of data and stores to the RES0 character array
{
while (!(IFG1 & UTXIFG0));
TXBUF0 = 0x00; // What is this? Why I need this? And what it do?
while (!(IFG1 & URXIFG0));
RES0[i] = RXBUF0; // What is this? Why I need this? And what it do? sending?
}
P2OUT |= ~CS_0; // Set CS "high"
configure_uart(); //config UART
for (i = 15; i < 18; i++) // Send Channel data to BT // What is this? Why I need this? And what it do? Apparently the original author of the code was communicating to more than one device, in this code snippet you don't see it here, but apparently the second device data was captured and they only transmitted data from channel 6 out the UART
{
while (!(IFG1 & UTXIFG0));
TXBUF0 = RES1[i]; // What is this? Why I need this? And what it do? This transmits channel 6 out the UART...but in your case it should be RES0[i]
// if(rx_on>1 && rx_data==0x00) goto STOP_AD; // What is this? Why I need this? And what it do? important This is the UART RX command to abort the reading
}
// rx_on = 0; // What is this? Why I need this? And what it do?
configure_spi(); // Setup SPI
}
// STOP_AD: // What is this? Why I need this? And what it do?
// rx_on = 0; // What is this? Why I need this? And what it do?
}
}
Best regards,
Bob B
Kaspars,
Looks like you are making great progress. When you read data from the ADS1298 you need to issue SCLKs from the MSP430. The way to do this is to place data in the transmit buffer. As the communication for the SPI is full-duplex, you need to take care when sending anything out via DIN so that it is not being misinterpreted as a command accidentally. The code author assigned 0x00 to the transmit buffer on data reads so the ADS1298 will consider a NOP is being given. On many data converters a NOP is considered to be either 0x00 or 0xFF.
Best regards,
Bob B
Dear Kaspars,
You can see the content of http://e2e.ti.com/support/data_converters/precision_data_converters/f/73/p/73715/268346.aspx#268346 . Please wait a minute, I will give you the modified code for you.
Hi Kaspars,
See th attached files please. 5543.Kaspars.rar
The Labview files is for LabVIEW 2009.
Sheng-Fu Chen
Hi Kasper,
I don't have a MatLab script to accumulate and read back the data, so on that point, I can't help. Regarding the 'decode', at the ADS1296 level and assuming you are using all eight channels, you will have 24 data bits x 9 (216 in total) that must be read between each DRDY impulse. The first 24 are the device status, the second 24 are CH0, the third 24 are CH1, etc... Each channel has information about what was going on at the analog inputs over a period of time. The ADS1296 is a delta-sigma converter that samples at the rate of the modulator clock and then accumulates/decimates down to your programmed data rate. While each conversion result does represent a voltage (for example 123uV), it does not necessarily refer to a specific instant in time.
For your application code, if you are going to stream data to a COM port, your going to have to package it in such a way that you insert a 'start of frame' to have your back end software know when/where new data starts. You could certainly include a time stamp there that says this sample was recieved at time 0,001 sec.