Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

I am trying to recieve voltage from MAX11040K

Status
Not open for further replies.

pnielsen

Member level 2
Member level 2
Joined
Mar 18, 2002
Messages
50
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
319
I was able to get the following code to zero all channels. But trying to read real voltages on all 4 channels?
Code is written for Cypress:


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <device.h>
uint32 Readvalue[4];
uint8 dummyvar;
uint8 i;
 
void main()
{
    /* Place your initialization/startup code here (e.g. MyInst_Start()) */
 
    CyGlobalIntEnable; /* Uncomment this line to enable global interrupts. */
    SPIM_Start();
    SPIM_ClearTxBuffer();
    SPIM_ClearRxBuffer();
//  LCD_Char_1_Start();
    
    
   
    SS_Write(0);                //digitalWrite(ADCCS, LOW);
    SPIM_WriteTxData(0x60);     //SPI.transfer(B01100000);     //address
    SPIM_WriteTxData(0x34);     //SPI.transfer(command1); command1 = B00110100
    while(!(SPIM_ReadTxStatus() & SPIM_STS_SPI_DONE));
    SS_Write(1);                //digitalWrite(ADCCS, HIGH);
 
    // For reading 3 bytes of data and sending a command byte.
 
    SS_Write(0);                //digitalWrite(ADCCS, LOW);
    CyDelayUs(1);               //Maximum time needed for the Output pin to get enabled is 20nsec, giving a delay of 1usec. 
                                //if (digitalRead(MISO) == LOW) {   // ADC Converter ready ?
    SPIM_WriteTxData(0xF0);     //SPI.transfer(B11110000);
    while(!(SPIM_ReadTxStatus() & SPIM_STS_SPI_DONE));
    
    SPIM_ClearRxBuffer();       //Read buffer will have two + one bytes of data, so clear the RX FIFO before reading 24 bits of data as you need.
    
    for(i=0;i<4;i++)            // Three 8 bit Write/Reads clears memory registers
    {
    
        SPIM_WriteTxData(0x00);     //b0=SPI.transfer(0);
        SPIM_WriteTxData(0x00);     //b0=SPI.transfer(0);
        SPIM_WriteTxData(0x00);     //b0=SPI.transfer(0); (24 dummy/ zero bits to be sent)
        
        while(!(SPIM_ReadTxStatus() & SPIM_STS_SPI_DONE)); // Wait till the three bytes are sent. Or check the RXStatus if some data has been received, but that doesn't tell if all 3 bytes have been received. Thus check when the Tx FIFO is sent completly.
        
        dummyvar = SPIM_ReadRxData();
        Readvalue[i]|=dummyvar;
        Readvalue[i]<<=8;
        dummyvar = SPIM_ReadRxData();
        Readvalue[i]|=dummyvar;
        Readvalue[i]<<=8;
        dummyvar = SPIM_ReadRxData();
        Readvalue[i]|=dummyvar;
    //    LCD_Char_1_Position(0,0) ;
    //    LCD_Char_1_PrintString(i); ? 
    //   if i = 0 
//         {
    //          LCD_Char
//           } 
    // May need UNION statement?
    }
    CyDelayUs(10000);
    SS_Write(1);
    CyDelayUs(1);
   
    
 
    
   for(;;)
    {
  }  
 
}
/* [] END OF FILE */
 
// Will use RS232 for com. Then RS232 to USB converter? Check Labview

 
Last edited by a moderator:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top