Join our technical discussions about Freescale Microcontrollers: M68HC12. (Freescale Semiconductor is a Subsidiary of Motorola).
|
Further to my posting of 2 days ago. I have got thus far with my SPI bus controlled ADC Chip. I do not seem to be able to transfer the data from the ADC chip to the Microcontrollers SPI bus any ideas? This code has been cut out of my test code to show members only this part. The SPI port one is configured as a MISO I am only interested in data comming from the ADC chip. I do not have any data going out and this line is not connected. Thanks Toby. SPIE_1 =0 ; /* disable Rx interrupt*/ SPE_1 = 1; /* Enable SPI port*/ SPTIE_1 = 0; /* disable Tx interrupt*/ MSTR_1 = /* place into master mode*/ if ((mode & 0x01) == 0x01) /* setup clock phase*/ { CPHA_1 = 1; } else { CPHA_1 = 0; } if ((mode & 0x02) == 0x02) /* set up clock polarity*/ { CPOL_1 = 1; } else { CPOL_1 = 0; } SSOE_1 = 0; /* disable SS pin*/ LSBF_1 = 0; /* Data transfere Most Significant Bit first*/ MODFEN_1 = 0; SPISWAI_1 = 0; SPC0_1 = 0; SPI1BR = baud; if (cmd & 0xa00000) { sprintf( str, " CMD is %x \r\n", cmd); PrintStr(serial_port, str); if (cmd & 0x010000) //check for keyboard input channel A0 { ANALOGUE_CHIP_ENABLE =1; ANALOGUE_CHANNEL_SELECT_A0=1; sprintf( str,"ADC Chip enabled and Chan A0 r\n\n"); PrintStr(serial_port, str); } if (cmd & 0x020000) //check for keyboard input channel A1 { ANALOGUE_CHIP_ENABLE =1; ANALOGUE_CHANNEL_SELECT_A1=1; sprintf( str, " ADC Chip enabled and Chan A1\r\n\n"); PrintStr(serial_port, str); } if (cmd & 0x040000) //check for keyboard input channel A1 { ANALOGUE_CHIP_ENABLE =1; ANALOGUE_CHANNEL_SELECT_A2=1; sprintf( str, " ADC Chip enabled and Chan A2r\n\n"); PrintStr(serial_port, str); } ANALOGUE_A_TO_D_CONV = 1; // Start ADC conv on off boardChip sprintf( str, " A to D conversion started/r/n"); PrintStr(serial_port, str); /******Need to wait one full clock cycle for convert to complete***/ if (CLOCK_SIGNAL == 0) { while (CLOCK_SIGNAL == 0) //Wait here until CLK goes high { } } if (CLOCK_SIGNAL == 1) { while (CLOCK_SIGNAL == 1) //Wait here until CLK goes low. { } } ANALOGUE_A_TO_D_CONV = 0; // Hold A to D conversion sprintf( str, " Hold Conversion/r/n"); PrintStr(serial_port, str); /***Get data from ADC Chip onto HCS12DP256 SPI Bus******/ while (SPRF_1 != 1) //Wait until SPRF Receive Interrupt Flag is set { } while (SPIF_1 != 1)//Wait until SPIF is set (transfer is complete) { } ANALOGUE_DATA = SPI1DR; sprintf( str, " Analogue byte %x/r/n", ANALOGUE_DATA); PrintStr(serial_port, str); Toby Merridan |
|
|
|
> Further to my posting of 2 days ago. I have got thus far with my SPI > bus controlled ADC Chip. I do not seem to be able to transfer the > data from the ADC chip to the Microcontrollers SPI bus any ideas? Be aware of MODF status bit. When MODF==1 you can't set MSTR bit. You can setup SS pin for output, clear MODF error and set MSTR. Or ensure that no external device drives SS pin low, wire pullup resistor to SS. Anyway you have to clear MODF error first. > This code has been cut out of my test code to show members only this > part. The SPI port one is configured as a MISO I am only interested Is it configured? Did you read MSTR==1? Try do it by hand - read and write using dbug or bdm debugger. Edward > in data comming from the ADC chip. I do not have any data going out > and this line is not connected. > > Thanks > > Toby. > > SPIE_1 =0 ; /* disable Rx interrupt*/ > SPE_1 = 1; /* Enable SPI port*/ > SPTIE_1 = 0; /* disable Tx interrupt*/ > MSTR_1 = /* place into master mode*/ > > if ((mode & 0x01) == 0x01) /* setup clock phase*/ > { > CPHA_1 = 1; > } > else > { > CPHA_1 = 0; > } > if ((mode & 0x02) == 0x02) /* set up clock polarity*/ > { > CPOL_1 = 1; > } > else > { > CPOL_1 = 0; > } > SSOE_1 = 0; /* disable SS pin*/ > LSBF_1 = 0; /* Data transfere Most Significant Bit first*/ > MODFEN_1 = 0; > SPISWAI_1 = 0; > SPC0_1 = 0; > SPI1BR = baud; > > if (cmd & 0xa00000) > { > sprintf( str, " CMD is %x \r\n", cmd); > PrintStr(serial_port, str); > if (cmd & 0x010000) //check for keyboard input channel A0 > { > ANALOGUE_CHIP_ENABLE =1; > ANALOGUE_CHANNEL_SELECT_A0=1; > sprintf( str,"ADC Chip enabled and Chan A0 r\n\n"); > PrintStr(serial_port, str); > } > > if (cmd & 0x020000) //check for keyboard input channel A1 > { > ANALOGUE_CHIP_ENABLE =1; > ANALOGUE_CHANNEL_SELECT_A1=1; > sprintf( str, " ADC Chip enabled and Chan A1\r\n\n"); > PrintStr(serial_port, str); > } > if (cmd & 0x040000) //check for keyboard input channel A1 > { > ANALOGUE_CHIP_ENABLE =1; > ANALOGUE_CHANNEL_SELECT_A2=1; > sprintf( str, " ADC Chip enabled and Chan A2r\n\n"); > PrintStr(serial_port, str); > } > ANALOGUE_A_TO_D_CONV = 1; // Start ADC conv on off boardChip > sprintf( str, " A to D conversion started/r/n"); > PrintStr(serial_port, str); > /******Need to wait one full clock cycle for convert to complete***/ > > if (CLOCK_SIGNAL == 0) > { > while (CLOCK_SIGNAL == 0) //Wait here until CLK goes high > { > } > } > if (CLOCK_SIGNAL == 1) > { > while (CLOCK_SIGNAL == 1) //Wait here until CLK goes low. > { > } > > } > ANALOGUE_A_TO_D_CONV = 0; // Hold A to D conversion > sprintf( str, " Hold Conversion/r/n"); > PrintStr(serial_port, str); > > /***Get data from ADC Chip onto HCS12DP256 SPI Bus******/ > > while (SPRF_1 != 1) //Wait until SPRF Receive Interrupt Flag is set > { > } > > while (SPIF_1 != 1)//Wait until SPIF is set (transfer is complete) > { > } > > ANALOGUE_DATA = SPI1DR; > > sprintf( str, " Analogue byte %x/r/n", ANALOGUE_DATA); > PrintStr(serial_port, str); > Toby Merridan > > -------------------------------------------------------- > To unsubscribe from this group, send an email to: > To learn more about Motorola Microcontrollers, please visit > http://www.motorola.com/mcu |
|
|
|
Thanks for replying Edward, Am I right in thinking that if MODFEN and SSOE bits are set low, SS does not have any function? Therefore it does not matter of they are pulled up/down or floating? I do not have anything connected to SS on my PCB at all.The reason I have not used the SS output to control my remote ADC chip is because I could not make head or tail of the operation in the SPI block manual, So I am using anther port/output for my ANALOGUE_CHIP_ENABLE. It will be too late to change it now. In my software I have MODFEN ==0 and SSOE ==0 is that right? The MODF bit should not be set in this case? Toby --- In , "Edward Karpicz" <karpicz@a...> wrote: > > Further to my posting of 2 days ago. I have got thus far > with my SPI > > bus controlled ADC Chip. I do not seem to be able to > transfer the > > data from the ADC chip to the Microcontrollers SPI bus any > ideas? > > Be aware of MODF status bit. When MODF==1 you can't set > MSTR bit. You can setup SS pin for output, clear MODF error > and set MSTR. Or ensure that no external device drives SS > pin low, > wire pullup resistor to SS. Anyway you have to clear MODF > error > first. > > > This code has been cut out of my test code to show members > only this > > part. The SPI port one is configured as a MISO I am only > interested > > Is it configured? Did you read MSTR==1? Try do it by > hand - read and > write using dbug or bdm debugger. > > Edward > > in data comming from the ADC chip. I do not have any data > going out > > and this line is not connected. > > > > Thanks > > > > Toby. > > > > > > > > SPIE_1 =0 ; /* disable Rx interrupt*/ > > SPE_1 = 1; /* Enable SPI port*/ > > SPTIE_1 = 0; /* disable Tx interrupt*/ > > MSTR_1 = /* place into master mode*/ > > > > if ((mode & 0x01) == 0x01) /* setup clock phase*/ > > { > > CPHA_1 = 1; > > } > > else > > { > > CPHA_1 = 0; > > } > > if ((mode & 0x02) == 0x02) /* set up clock > polarity*/ > > { > > CPOL_1 = 1; > > } > > else > > { > > CPOL_1 = 0; > > } > > SSOE_1 = 0; /* disable SS pin*/ > > LSBF_1 = 0; /* Data transfere Most Significant > Bit first*/ > > MODFEN_1 = 0; > > SPISWAI_1 = 0; > > SPC0_1 = 0; > > SPI1BR = baud; > > > > if (cmd & 0xa00000) > > { > > sprintf( str, " CMD is %x \r\n", cmd); > > PrintStr(serial_port, str); > > if (cmd & 0x010000) //check for keyboard input > channel A0 > > { > > ANALOGUE_CHIP_ENABLE =1; > > ANALOGUE_CHANNEL_SELECT_A0=1; > > sprintf( str,"ADC Chip enabled and Chan A0 r\n\n"); > > PrintStr(serial_port, str); > > } > > > > if (cmd & 0x020000) //check for keyboard input > channel A1 > > { > > ANALOGUE_CHIP_ENABLE =1; > > ANALOGUE_CHANNEL_SELECT_A1=1; > > sprintf( str, " ADC Chip enabled and Chan A1\r\n\n"); > > PrintStr(serial_port, str); > > } > > if (cmd & 0x040000) //check for keyboard input > channel A1 > > { > > ANALOGUE_CHIP_ENABLE =1; > > ANALOGUE_CHANNEL_SELECT_A2=1; > > sprintf( str, " ADC Chip enabled and Chan A2r\n\n"); > > PrintStr(serial_port, str); > > } > > > > > > ANALOGUE_A_TO_D_CONV = 1; // Start ADC conv on off > boardChip > > sprintf( str, " A to D conversion started/r/n"); > > PrintStr(serial_port, str); > > > > > > /******Need to wait one full clock cycle for convert to > complete***/ > > > > if (CLOCK_SIGNAL == 0) > > { > > while (CLOCK_SIGNAL == 0) //Wait here until CLK goes > high > > { > > } > > } > > if (CLOCK_SIGNAL == 1) > > { > > while (CLOCK_SIGNAL == 1) //Wait here until CLK goes > low. > > { > > } > > > > } > > > > > > ANALOGUE_A_TO_D_CONV = 0; // Hold A to D conversion > > sprintf( str, " Hold Conversion/r/n"); > > PrintStr(serial_port, str); > > > > /***Get data from ADC Chip onto HCS12DP256 SPI Bus******/ > > > > while (SPRF_1 != 1) //Wait until SPRF Receive Interrupt > Flag is set > > { > > } > > > > while (SPIF_1 != 1)//Wait until SPIF is set (transfer is > complete) > > { > > } > > > > ANALOGUE_DATA = SPI1DR; > > > > sprintf( str, " Analogue byte %x/r/n", ANALOGUE_DATA); > > PrintStr(serial_port, str); > > > > > > > > > > > > Toby Merridan > > > > > > > > -------------------------------------------------------- > > To unsubscribe from this group, send an email to: > > > > > > To learn more about Motorola Microcontrollers, please > visit > > http://www.motorola.com/mcu > > > > > > > > > |
|
----- Original Message ----- From: <> To: <> Sent: Wednesday, January 29, 2003 4:12 PM Subject: [68HC12] Re: DP256 SPI help > Thanks for replying Edward, > > Am I right in thinking that if MODFEN and SSOE bits are set low, SS > does not have any function? Therefore it does not matter of they are > pulled up/down or floating? I do not have anything connected to SS on > my PCB at all.The reason I have not used the SS output to control my > remote ADC chip is because I could not make head or tail of the > operation in the SPI block manual, So I am using anther port/output > for my ANALOGUE_CHIP_ENABLE. It will be too late to change it now. > > In my software I have MODFEN ==0 and SSOE ==0 is that right? The MODF > bit should not be set in this case? > > Toby > --- In , "Edward Karpicz" <karpicz@a...> wrote: > > > Further to my posting of 2 days ago. I have got thus far > > with my SPI > > > bus controlled ADC Chip. I do not seem to be able to > > transfer the > > > data from the ADC chip to the Microcontrollers SPI bus any > > ideas? > > > > Be aware of MODF status bit. When MODF==1 you can't set > > MSTR bit. You can setup SS pin for output, clear MODF error > > and set MSTR. Or ensure that no external device drives SS > > pin low, > > wire pullup resistor to SS. Anyway you have to clear MODF > > error > > first. > > > > > This code has been cut out of my test code to show members > > only this > > > part. The SPI port one is configured as a MISO I am only > > interested > > > > Is it configured? Did you read MSTR==1? Try do it by > > hand - read and > > write using dbug or bdm debugger. > > > > Edward > > > > > > > in data comming from the ADC chip. I do not have any data > > going out > > > and this line is not connected. > > > > > > Thanks > > > > > > Toby. > > > > > > > > > > > > SPIE_1 =0 ; /* disable Rx interrupt*/ > > > SPE_1 = 1; /* Enable SPI port*/ > > > SPTIE_1 = 0; /* disable Tx interrupt*/ > > > MSTR_1 = /* place into master mode*/ > > > > > > if ((mode & 0x01) == 0x01) /* setup clock phase*/ > > > { > > > CPHA_1 = 1; > > > } > > > else > > > { > > > CPHA_1 = 0; > > > } > > > if ((mode & 0x02) == 0x02) /* set up clock > > polarity*/ > > > { > > > CPOL_1 = 1; > > > } > > > else > > > { > > > CPOL_1 = 0; > > > } > > > SSOE_1 = 0; /* disable SS pin*/ > > > LSBF_1 = 0; /* Data transfere Most Significant > > Bit first*/ > > > MODFEN_1 = 0; > > > SPISWAI_1 = 0; > > > SPC0_1 = 0; > > > SPI1BR = baud; > > > > > > if (cmd & 0xa00000) > > > { > > > sprintf( str, " CMD is %x \r\n", cmd); > > > PrintStr(serial_port, str); > > > if (cmd & 0x010000) //check for keyboard input > > channel A0 > > > { > > > ANALOGUE_CHIP_ENABLE =1; > > > ANALOGUE_CHANNEL_SELECT_A0=1; > > > sprintf( str,"ADC Chip enabled and Chan A0 r\n\n"); > > > PrintStr(serial_port, str); > > > } > > > > > > if (cmd & 0x020000) //check for keyboard input > > channel A1 > > > { > > > ANALOGUE_CHIP_ENABLE =1; > > > ANALOGUE_CHANNEL_SELECT_A1=1; > > > sprintf( str, " ADC Chip enabled and Chan A1\r\n\n"); > > > PrintStr(serial_port, str); > > > } > > > if (cmd & 0x040000) //check for keyboard input > > channel A1 > > > { > > > ANALOGUE_CHIP_ENABLE =1; > > > ANALOGUE_CHANNEL_SELECT_A2=1; > > > sprintf( str, " ADC Chip enabled and Chan A2r\n\n"); > > > PrintStr(serial_port, str); > > > } > > > > > > > > > ANALOGUE_A_TO_D_CONV = 1; // Start ADC conv on off > > boardChip > > > sprintf( str, " A to D conversion started/r/n"); > > > PrintStr(serial_port, str); > > > > > > > > > /******Need to wait one full clock cycle for convert to > > complete***/ > > > > > > if (CLOCK_SIGNAL == 0) > > > { > > > while (CLOCK_SIGNAL == 0) //Wait here until CLK goes > > high > > > { > > > } > > > } > > > if (CLOCK_SIGNAL == 1) > > > { > > > while (CLOCK_SIGNAL == 1) //Wait here until CLK goes > > low. > > > { > > > } > > > > > > } > > > > > > > > > ANALOGUE_A_TO_D_CONV = 0; // Hold A to D conversion > > > sprintf( str, " Hold Conversion/r/n"); > > > PrintStr(serial_port, str); > > > > > > /***Get data from ADC Chip onto HCS12DP256 SPI Bus******/ > > > > > > while (SPRF_1 != 1) //Wait until SPRF Receive Interrupt > > Flag is set > > > { > > > } > > > > > > while (SPIF_1 != 1)//Wait until SPIF is set (transfer is > > complete) > > > { > > > } > > > > > > ANALOGUE_DATA = SPI1DR; > > > > > > sprintf( str, " Analogue byte %x/r/n", ANALOGUE_DATA); > > > PrintStr(serial_port, str); > > > > > > > > > > > > > > > > > > Toby Merridan > > > > > > > > > > > > -------------------------------------------------------- > > > To unsubscribe from this group, send an email to: > > > > > > > > > To learn more about Motorola Microcontrollers, please > > visit > > > http://www.motorola.com/mcu > > > > > > > > > > > > > > > -------------------------------------------------------- > To unsubscribe from this group, send an email to: > To learn more about Motorola Microcontrollers, please visit > http://www.motorola.com/mcu |
|
> Thanks for replying Edward, > > Am I right in thinking that if MODFEN and SSOE bits are set low, SS > does not have any function? Therefore it does not matter of they are Ups, DP256's SPI is bit different than D60A,DG128A and MODFEN is good feature but as "MC9S12DP256 advance information" v1.1 says setting MODFEN low doesn't clear MODF flag. If after reset MODFEN==0 MODF should be ==0 too but it's a good idea to check SPISR first. Edward > pulled up/down or floating? I do not have anything connected to SS on > my PCB at all.The reason I have not used the SS output to control my > remote ADC chip is because I could not make head or tail of the > operation in the SPI block manual, So I am using anther port/output > for my ANALOGUE_CHIP_ENABLE. It will be too late to change it now. > > In my software I have MODFEN ==0 and SSOE ==0 is that right? The MODF > bit should not be set in this case? > > Toby > --- In , "Edward Karpicz" <karpicz@a...> wrote: > > > Further to my posting of 2 days ago. I have got thus far > > with my SPI > > > bus controlled ADC Chip. I do not seem to be able to > > transfer the > > > data from the ADC chip to the Microcontrollers SPI bus any > > ideas? > > > > Be aware of MODF status bit. When MODF==1 you can't set > > MSTR bit. You can setup SS pin for output, clear MODF error > > and set MSTR. Or ensure that no external device drives SS > > pin low, > > wire pullup resistor to SS. Anyway you have to clear MODF > > error > > first. > > > > > This code has been cut out of my test code to show members > > only this > > > part. The SPI port one is configured as a MISO I am only > > interested > > > > Is it configured? Did you read MSTR==1? Try do it by > > hand - read and > > write using dbug or bdm debugger. > > > > Edward > > > > > > > in data comming from the ADC chip. I do not have any data > > going out > > > and this line is not connected. > > > > > > Thanks > > > > > > Toby. > > > > > > > > > > > > SPIE_1 =0 ; /* disable Rx interrupt*/ > > > SPE_1 = 1; /* Enable SPI port*/ > > > SPTIE_1 = 0; /* disable Tx interrupt*/ > > > MSTR_1 = /* place into master mode*/ > > > > > > if ((mode & 0x01) == 0x01) /* setup clock phase*/ > > > { > > > CPHA_1 = 1; > > > } > > > else > > > { > > > CPHA_1 = 0; > > > } > > > if ((mode & 0x02) == 0x02) /* set up clock > > polarity*/ > > > { > > > CPOL_1 = 1; > > > } > > > else > > > { > > > CPOL_1 = 0; > > > } > > > SSOE_1 = 0; /* disable SS pin*/ > > > LSBF_1 = 0; /* Data transfere Most Significant > > Bit first*/ > > > MODFEN_1 = 0; > > > SPISWAI_1 = 0; > > > SPC0_1 = 0; > > > SPI1BR = baud; > > > > > > if (cmd & 0xa00000) > > > { > > > sprintf( str, " CMD is %x \r\n", cmd); > > > PrintStr(serial_port, str); > > > if (cmd & 0x010000) //check for keyboard input > > channel A0 > > > { > > > ANALOGUE_CHIP_ENABLE =1; > > > ANALOGUE_CHANNEL_SELECT_A0=1; > > > sprintf( str,"ADC Chip enabled and Chan A0 r\n\n"); > > > PrintStr(serial_port, str); > > > } > > > > > > if (cmd & 0x020000) //check for keyboard input > > channel A1 > > > { > > > ANALOGUE_CHIP_ENABLE =1; > > > ANALOGUE_CHANNEL_SELECT_A1=1; > > > sprintf( str, " ADC Chip enabled and Chan A1\r\n\n"); > > > PrintStr(serial_port, str); > > > } > > > if (cmd & 0x040000) //check for keyboard input > > channel A1 > > > { > > > ANALOGUE_CHIP_ENABLE =1; > > > ANALOGUE_CHANNEL_SELECT_A2=1; > > > sprintf( str, " ADC Chip enabled and Chan A2r\n\n"); > > > PrintStr(serial_port, str); > > > } > > > > > > > > > ANALOGUE_A_TO_D_CONV = 1; // Start ADC conv on off > > boardChip > > > sprintf( str, " A to D conversion started/r/n"); > > > PrintStr(serial_port, str); > > > > > > > > > /******Need to wait one full clock cycle for convert to > > complete***/ > > > > > > if (CLOCK_SIGNAL == 0) > > > { > > > while (CLOCK_SIGNAL == 0) //Wait here until CLK goes > > high > > > { > > > } > > > } > > > if (CLOCK_SIGNAL == 1) > > > { > > > while (CLOCK_SIGNAL == 1) //Wait here until CLK goes > > low. > > > { > > > } > > > > > > } > > > > > > > > > ANALOGUE_A_TO_D_CONV = 0; // Hold A to D conversion > > > sprintf( str, " Hold Conversion/r/n"); > > > PrintStr(serial_port, str); > > > > > > /***Get data from ADC Chip onto HCS12DP256 SPI Bus******/ > > > > > > while (SPRF_1 != 1) //Wait until SPRF Receive Interrupt > > Flag is set > > > { > > > } > > > > > > while (SPIF_1 != 1)//Wait until SPIF is set (transfer is > > complete) > > > { > > > } > > > > > > ANALOGUE_DATA = SPI1DR; > > > > > > sprintf( str, " Analogue byte %x/r/n", ANALOGUE_DATA); > > > PrintStr(serial_port, str); > > > > > > > > > > > > > > > > > > Toby Merridan > > > > > > > > > > > > -------------------------------------------------------- > > > To unsubscribe from this group, send an email to: > > > > > > > > > To learn more about Motorola Microcontrollers, please > > visit > > > http://www.motorola.com/mcu > > > > > > > > > > > > > > > -------------------------------------------------------- > To unsubscribe from this group, send an email to: > To learn more about Motorola Microcontrollers, please visit > http://www.motorola.com/mcu |
|
Toby, Where is the clock coming from for the data transfer back to the HC12? The Master supplies the SPI clock. On the 812A4, at least, the way to get a Master-mode CPU to supply that clock signal is to write a byte to the SPI data register. Even if you are throwing away the SPI output, you have to "output" a byte to generate the eight clock pulses that the slave needs if it is to shift the data back to the CPU. Have you looked at the SPI clock line with a 'scope to confirm that you're getting the right pulses? Do you see any activity on the MISO line when you expect to see it? I'm confused by the "if (CLOCK_SIGNAL ..." code. Your earlier description of the problem indicated that the ADC depended on the SPI clock to control its conversion and data transfer: One clock for the conversion, and 14 for data. If that's the case, what is CLOCK_SIGNAL? If it is an externally- generated SPI clock, the DP256's SPI interface should be in slave mode, not master. I'm no SPI expert, so forgive me if these suggestions are completely off track. Stephen -- Stephen Trier Technical Development Lab Cleveland FES Center / CWRU / KG8IH |
|
|
|
Hi Stephen, In between posts I have been thinking about just that point. I do not get a clock at all from the Master-mode CPU on the scope! Do Ineed to send a byte to the SPDR to get it moving? --- In , Stephen Trier <sct@p...> wrote: > Toby, > > Where is the clock coming from for the data transfer back to the HC12? > The Master supplies the SPI clock. On the 812A4, at least, the way to get > a Master-mode CPU to supply that clock signal is to write a byte to the SPI > data register. Even if you are throwing away the SPI output, you have to > "output" a byte to generate the eight clock pulses that the slave needs if > it is to shift the data back to the CPU. > > Have you looked at the SPI clock line with a 'scope to confirm that you're > getting the right pulses? Do you see any activity on the MISO line when > you expect to see it? > > I'm confused by the "if (CLOCK_SIGNAL ..." code. Your earlier description > of the problem indicated that the ADC depended on the SPI clock to control > its conversion and data transfer: One clock for the conversion, and 14 for > data. If that's the case, what is CLOCK_SIGNAL? If it is an externally- > generated SPI clock, the DP256's SPI interface should be in slave mode, > not master. > > I'm no SPI expert, so forgive me if these suggestions are completely off > track. > > Stephen > > -- > Stephen Trier > Technical Development Lab > Cleveland FES Center / CWRU > sct@p... / KG8IH |
|
|
|
At 10:49 AM 1/29/2003 +0000, you wrote: >This code has been cut out of my test code to show members only this >part. The SPI port one is configured as a MISO I am only interested >in data comming from the ADC chip. I do not have any data going out >and this line is not connected. With SPI you always have data going both ways. The master transmits data on MOSI (master out slave in) and simultaneously reads data on MISO (master in slave out). The transaction is clocked using SCK (serial clock). If you do not hook MISO to MISO on the ADC, the ADC will read random stuff on MISO. You will have to look through the ADC docs to see if you are supposed to be sending a data word while receiving data. Typically you would send the number of the ADC channel to be read on the next cycle or the conversion parameters to be used on the next read. Be sure you have the clock phasing and idle levels set to what the ADC is expecting. SCK can be programmed to idle high or low and sample on the high going edge or the low going edge. This is to accommodate the various slaves out there. Be sure that you are setting the word length appropriate for the ADC. A 12 bit ADC may need 12 clock cycles, 16 cycles, or two 8 cycle reads to get the data transfered, once again depending on what the ADC is expecting. Andrei |
|
At 04:44 PM 1/29/03 -0000, Toby Merridan wrote: >Do Ineed to send a byte to the SPDR to get it moving? Yes, that's exactly it. SPI doesn't have a transmit-only or receive-only operation. In order to receive a byte, the SPI master must transmit a byte by writing to SPxDR. It must write exactly one byte for every byte it wishes to receive. Stephen -- Stephen Trier Technical Development Lab Cleveland FES Center / CWRU / KG8IH |
|
|
|
So Stephen, What about the following: Initialise SPI bus 1 SPIE_1=0; //SPI interrupts disabled. SPE_1=1; //SPI port pins dedicated to SPI funtions. SPTIE_1=0; //SPTEF Interrupt disabled. MSTR_1=1; //SPI Master mode. CPHA_1=1 //SPI CLock Phase first clock edge. CPOL_1=1; //SPI clock polarity bit active low. SSOE_1=0; //SPI SLave Select Out[ut disabled. LSBF_1=0; //SPI Data transfer MSB MODFEN_1=0; //SPI Disable MODF error. SPISWAI_1=0; //SPI clock operates normally in wait mode. SPI1BR=1; //SPI baud rate register. I have to enable the ADC chip as it is not a true SPI device therefore: /**Chip select**/ ANALOGUE_CHIP_ENABLE =1 //CPU_PORT_H.bit3 output to external MUX. /**Channel Select**/ ANALOGUE_CHANNEL_SELECT_A0 = 1 // CPU_PORT_E.bit3 out to ext MUX /**Initialise ADC Converion****/ ANALOGUE_A_TO_D_CONV = 1 //CPU_PORT_A.bit7 /***Need to wait one full clock signal (suggestions?)***/ if (CLOCK_SIGNAL ==0) //CLOCK_SIGNAL is CPU_PORTH.bit2 ? { while(CLOCK_SIGNAL ==0) //Wait here until CLCK_SIGNAL goes high { } { if (CLOCK_SIGNAL==1) { while(CLOCK_SIGNAL==1) //Wait here until CLOCK_SIGNAL goes low { } { /****Hold ADC Conversion after 1 clock cycle****/ ANALOGUE_A_TO_D_CONV = 0 //CONV on ADC chip needs to be held low /******Get the SPI moving********/ while (SPTEF_1 !=1) //Wait until SPTEF is set (transmit transfer) { } while (SPIF_1 !=1) //Wait until SPIF is set (receive transfer) { } clear_spif = SPI1SR //Read SPISR (to intitiate clearing SPIF & SPTEF?) ANALOGUE_DATA = SPI1DR; //Read SPIDR (will now clear SPIF and SPTEF ?) Hopefully I will get there in the end!! Look forward to your comments Toby. /*****Data should now be in ANALOGUE_DATA********/ Not sure how I get the 12 bits from the ADC (ADS7818 by the way) --- In , Stephen Trier <sct@p...> wrote: > At 04:44 PM 1/29/03 -0000, Toby Merridan wrote: > >Do Ineed to send a byte to the SPDR to get it moving? > > Yes, that's exactly it. SPI doesn't have a transmit-only or receive-only > operation. In order to receive a byte, the SPI master must transmit a byte > by writing to SPxDR. It must write exactly one byte for every byte it wishes > to receive. > > Stephen > > -- > Stephen Trier > Technical Development Lab > Cleveland FES Center / CWRU > sct@p... / KG8IH |
|
|
|
Sorry, missed a bit in the code! --- In , "hellfire1272000 <toby.merridan@s...>" <toby.merridan@s...> wrote: > So Stephen, > > What about the following: > > Initialise SPI bus 1 > > SPIE_1=0; //SPI interrupts disabled. > SPE_1=1; //SPI port pins dedicated to SPI funtions. > SPTIE_1=0; //SPTEF Interrupt disabled. > MSTR_1=1; //SPI Master mode. > CPHA_1=1 //SPI CLock Phase first clock edge. > CPOL_1=1; //SPI clock polarity bit active low. > SSOE_1=0; //SPI SLave Select Out[ut disabled. > LSBF_1=0; //SPI Data transfer MSB > MODFEN_1=0; //SPI Disable MODF error. > SPISWAI_1=0; //SPI clock operates normally in wait mode. > SPI1BR=1; //SPI baud rate register. > > I have to enable the ADC chip as it is not a true SPI device > therefore: > > /**Chip select**/ > ANALOGUE_CHIP_ENABLE =1 //CPU_PORT_H.bit3 output to external MUX. > > /**Channel Select**/ > ANALOGUE_CHANNEL_SELECT_A0 = 1 // CPU_PORT_E.bit3 out to ext MUX > > /**Initialise ADC Converion****/ > > ANALOGUE_A_TO_D_CONV = 1 //CPU_PORT_A.bit7 > > /***Need to wait one full clock signal (suggestions?)***/ > > if (CLOCK_SIGNAL ==0) //CLOCK_SIGNAL is CPU_PORTH.bit2 ? > { > while(CLOCK_SIGNAL ==0) //Wait here until CLCK_SIGNAL goes high > { > } > { > > if (CLOCK_SIGNAL==1) > { > while(CLOCK_SIGNAL==1) //Wait here until CLOCK_SIGNAL goes low > { > } > { > > /****Hold ADC Conversion after 1 clock cycle****/ > > ANALOGUE_A_TO_D_CONV = 0 //CONV on ADC chip needs to be held low > > /******Get the SPI moving********/ > while (SPTEF_1 !=1) //Wait until SPTEF is set (transmit transfer) > { > } > SPI1DR = 0xf;// write anything to the data register to get it moving > while (SPIF_1 !=1) //Wait until SPIF is set (receive transfer) > { > } > > clear_spif = SPI1SR //Read SPISR (to intitiate clearing SPIF & SPTEF?) > ANALOGUE_DATA = SPI1DR; //Read SPIDR (will now clear SPIF and SPTEF ?) > > Hopefully I will get there in the end!! > > Look forward to your comments > > Toby. > > /*****Data should now be in ANALOGUE_DATA********/ > > Not sure how I get the 12 bits from the ADC (ADS7818 by the way) > > --- In , Stephen Trier <sct@p...> wrote: > > At 04:44 PM 1/29/03 -0000, Toby Merridan wrote: > > >Do Ineed to send a byte to the SPDR to get it moving? > > > > Yes, that's exactly it. SPI doesn't have a transmit-only or > receive-only > > operation. In order to receive a byte, the SPI master must > transmit a byte > > by writing to SPxDR. It must write exactly one byte for every byte > it wishes > > to receive. > > > > Stephen > > > > -- > > Stephen Trier > > Technical Development Lab > > Cleveland FES Center / CWRU > > sct@p... / KG8IH |
|
|
|
Toby, It's still impossible, fundamentally, to answer your questions because of inadequate information about your hardware setup. >> if (CLOCK_SIGNAL ==0) //CLOCK_SIGNAL is CPU_PORTH.bit2 ? >> { >> while(CLOCK_SIGNAL ==0) //Wait here until CLCK_SIGNAL goes high >> { >> } >> { >> >> if (CLOCK_SIGNAL==1) >> { >> while(CLOCK_SIGNAL==1) //Wait here until CLOCK_SIGNAL goes low >> { >> } >> { The above code continues to confuse me. Where is the AD7818's CLK line tied? It should be connected to SCK for the SPI port. If CLOCK_SIGNAL is tied to the AD7818's CLK line, perhaps there is some confusion about inputs and outputs. The AD7818 CLK line is an input. Now, I don't know what the DP256's SPI interface looks like, so here is the way I would do it on the 812A4. On the A4's SPI interface, the SPIF flag bit gets set when any SPI transfer completes. Note that I represent the flag bits a little differently that you do, but that's easy to change to fit your coding style. unsigned char tmp1, tmp2; /* Start conversion */ ANALOGUE_A_TO_D_CONV = 0; /* Clock and read the first 8 bits */ SP0DR = 0; /* Generate 8 clock cycles by "sending" a byte */ while (!(SP0SR & SPIF)) ; /* Wait for the 8 cycles to complete */ tmp1 = SP0DR; /* Read the first byte of data. */ /* Clock and read the second 8 bits */ SP0DR = 0; /* Generate 8 clock cycles by "sending" a byte */ while (!(SP0SR & SPIF)) ; /* Wait for the 8 cycles to complete */ tmp2 = SP0DR; /* Read the second byte of data. */ /* End conversion */ ANALOGUE_A_TO_D_CONV = 1; /* * At this point, the data are in tmp1 and tmp2. * tmp1 has 7 MSBs of the result, right-aligned. * tmp2 has 5 LSBs of the result, left-aligned. * Combine the two into a 16 bit number, then handle the alignment. */ analogue_data = (((unsigned) tmp1 << 8) + (unsigned) tmp2) >> 3; analogue_data &= 0x0FFF; /* * Note: the ">> 3" above may be off-by-one. Check your results * to see whether ">> 2" or ">> 4" might actually be correct. */ This implementation follows directly from figure 9 of the ADS7818 data sheet, "Typical SPI/QSPI Interface Timing", and the accompanying text, both of which are worth studying. This code clocks the converter for 16 cycles, not 13, but that is fine. The documentation specifically says the part will ignore the extra cycles. The only cost is the extra right-shift (">> 3") in the penultimate line of code. Stephen -- Stephen Trier Technical Development Lab Cleveland FES Center / CWRU / KG8IH |
|
|
|
Thanks Stephen, That has been very helpful. Just to clarify: the AdS7818 is tied to the SPI CLK line as you say, sorry I havn't made it clearer. To test I have via a RS232 link enabled the ADC Channels and chip via a keyboard and put the sampling and SPI code into a loop so that I can see what is happening. I am now seeing tmp1 and tmp2 and analogue_data but their values are zero! As there is about 1/2 volt on the ADC input I would expect to see the bytes with some data in them. My scope will not lock onto the data byte as the clock is too noisy.I thought that I should at least see a value other than zero in tmp2 of the least significant bits? I am confidant that the SPI bus is working I am just worried about the values of tmp1 tmp2 and analogue_data. Your help has been most appreciated I hope that I can reciprocate some time! If the MC9S12DP256 manual was clearer it would be much easier! --- In , Stephen Trier <sct@p...> wrote: > Toby, > > It's still impossible, fundamentally, to answer your questions because > of inadequate information about your hardware setup. > > >> if (CLOCK_SIGNAL ==0) //CLOCK_SIGNAL is CPU_PORTH.bit2 ? > >> { > >> while(CLOCK_SIGNAL ==0) //Wait here until CLCK_SIGNAL goes high > >> { > >> } > >> { > >> > >> if (CLOCK_SIGNAL==1) > >> { > >> while(CLOCK_SIGNAL==1) //Wait here until CLOCK_SIGNAL goes low > >> { > >> } > >> { > > The above code continues to confuse me. > > Where is the AD7818's CLK line tied? It should be connected to SCK for > the SPI port. > > If CLOCK_SIGNAL is tied to the AD7818's CLK line, perhaps there is some > confusion about inputs and outputs. The AD7818 CLK line is an input. > > Now, I don't know what the DP256's SPI interface looks like, so here is > the way I would do it on the 812A4. On the A4's SPI interface, the SPIF > flag bit gets set when any SPI transfer completes. Note that I represent > the flag bits a little differently that you do, but that's easy to change > to fit your coding style. > > unsigned char tmp1, tmp2; > > /* Start conversion */ > ANALOGUE_A_TO_D_CONV = 0; > > /* Clock and read the first 8 bits */ > SP0DR = 0; /* Generate 8 clock cycles by "sending" a byte */ > while (!(SP0SR & SPIF)) > ; /* Wait for the 8 cycles to complete */ > tmp1 = SP0DR; /* Read the first byte of data. */ > > /* Clock and read the second 8 bits */ > SP0DR = 0; /* Generate 8 clock cycles by "sending" a byte */ > while (!(SP0SR & SPIF)) > ; /* Wait for the 8 cycles to complete */ > tmp2 = SP0DR; /* Read the second byte of data. */ > > /* End conversion */ > ANALOGUE_A_TO_D_CONV = 1; > > /* > * At this point, the data are in tmp1 and tmp2. > * tmp1 has 7 MSBs of the result, right-aligned. > * tmp2 has 5 LSBs of the result, left-aligned. > * Combine the two into a 16 bit number, then handle the alignment. > */ > > analogue_data = (((unsigned) tmp1 << 8) + (unsigned) tmp2) >> 3; > analogue_data &= 0x0FFF; > > /* > * Note: the ">> 3" above may be off-by-one. Check your results > * to see whether ">> 2" or ">> 4" might actually be correct. > */ > > This implementation follows directly from figure 9 of the ADS7818 data > sheet, "Typical SPI/QSPI Interface Timing", and the accompanying text, > both of which are worth studying. > > This code clocks the converter for 16 cycles, not 13, but that is fine. > The documentation specifically says the part will ignore the extra cycles. > The only cost is the extra right-shift (">> 3") in the penultimate line > of code. > > Stephen > > -- > Stephen Trier > Technical Development Lab > Cleveland FES Center / CWRU > sct@p... / KG8IH |
|
Your SPI clk should not be noisy. If it truly is noisy (not a setup with scope
problem) that may be why it does not work. In 20 years of SPI work I have never seen a
noisy SPI clock in a working system. Dale Kelley -----Original Message----- From: hellfire1272000 <> [mailto:] Sent: Friday, January 31, 2003 6:28 AM To: Subject: [68HC12] Re: DP256 SPI help Thanks Stephen, That has been very helpful. Just to clarify: the AdS7818 is tied to the SPI CLK line as you say, sorry I havn't made it clearer. To test I have via a RS232 link enabled the ADC Channels and chip via a keyboard and put the sampling and SPI code into a loop so that I can see what is happening. I am now seeing tmp1 and tmp2 and analogue_data but their values are zero! As there is about 1/2 volt on the ADC input I would expect to see the bytes with some data in them. My scope will not lock onto the data byte as the clock is too noisy.I thought that I should at least see a value other than zero in tmp2 of the least significant bits? I am confidant that the SPI bus is working I am just worried about the values of tmp1 tmp2 and analogue_data. Your help has been most appreciated I hope that I can reciprocate some time! If the MC9S12DP256 manual was clearer it would be much easier! --- In , Stephen Trier <sct@p...> wrote: > Toby, > > It's still impossible, fundamentally, to answer your questions because > of inadequate information about your hardware setup. > > >> if (CLOCK_SIGNAL ==0) //CLOCK_SIGNAL is CPU_PORTH.bit2 ? > >> { > >> while(CLOCK_SIGNAL ==0) //Wait here until CLCK_SIGNAL goes high > >> { > >> } > >> { > >> > >> if (CLOCK_SIGNAL==1) > >> { > >> while(CLOCK_SIGNAL==1) //Wait here until CLOCK_SIGNAL goes low > >> { > >> } > >> { > > The above code continues to confuse me. > > Where is the AD7818's CLK line tied? It should be connected to SCK for > the SPI port. > > If CLOCK_SIGNAL is tied to the AD7818's CLK line, perhaps there is some > confusion about inputs and outputs. The AD7818 CLK line is an input. > > Now, I don't know what the DP256's SPI interface looks like, so here is > the way I would do it on the 812A4. On the A4's SPI interface, the SPIF > flag bit gets set when any SPI transfer completes. Note that I represent > the flag bits a little differently that you do, but that's easy to change > to fit your coding style. > > unsigned char tmp1, tmp2; > > /* Start conversion */ > ANALOGUE_A_TO_D_CONV = 0; > > /* Clock and read the first 8 bits */ > SP0DR = 0; /* Generate 8 clock cycles by "sending" a byte */ > while (!(SP0SR & SPIF)) > ; /* Wait for the 8 cycles to complete */ > tmp1 = SP0DR; /* Read the first byte of data. */ > > /* Clock and read the second 8 bits */ > SP0DR = 0; /* Generate 8 clock cycles by "sending" a byte */ > while (!(SP0SR & SPIF)) > ; /* Wait for the 8 cycles to complete */ > tmp2 = SP0DR; /* Read the second byte of data. */ > > /* End conversion */ > ANALOGUE_A_TO_D_CONV = 1; > > /* > * At this point, the data are in tmp1 and tmp2. > * tmp1 has 7 MSBs of the result, right-aligned. > * tmp2 has 5 LSBs of the result, left-aligned. > * Combine the two into a 16 bit number, then handle the alignment. > */ > > analogue_data = (((unsigned) tmp1 << 8) + (unsigned) tmp2) >> 3; > analogue_data &= 0x0FFF; > > /* > * Note: the ">> 3" above may be off-by-one. Check your results > * to see whether ">> 2" or ">> 4" might actually be correct. > */ > > This implementation follows directly from figure 9 of the ADS7818 data > sheet, "Typical SPI/QSPI Interface Timing", and the accompanying text, > both of which are worth studying. > > This code clocks the converter for 16 cycles, not 13, but that is fine. > The documentation specifically says the part will ignore the extra cycles. > The only cost is the extra right-shift (">> 3") in the penultimate line > of code. > > Stephen > > -- > Stephen Trier > Technical Development Lab > Cleveland FES Center / CWRU > sct@p... / KG8IH -------------------------------------------------------- To unsubscribe from this group, send an email to: To learn more about Motorola Microcontrollers, please visit http://www.motorola.com/mcu ------------------------------------------------------------------------------------------------ This message is for the designated recipient only and may contain privileged, proprietary, or otherwise private information. If you have received it in error, please notify the sender immediately and delete the original. Any unauthorized use of this email is prohibited. ------------------------------------------------------------------------------------------------ |