wnorcott 2 Posted May 18, 2015 Share Posted May 18, 2015 The MSP430G2553 has the UCSI hardware chip that supports UART, I2C and SPI. According to the user guide and a tutorial I read over on the Argenox Technologies web site (quote): The MSP430G2553 has two SPI interfaces, mapped with the following pins: UCA0 P1.1 Quote Link to post Share on other sites
spirilis 1,265 Posted May 18, 2015 Share Posted May 18, 2015 You'd have to clone the library since it references the UCB registers directly. Then of course change pins_energia.h as you have seen already Quote Link to post Share on other sites
wnorcott 2 Posted May 18, 2015 Author Share Posted May 18, 2015 I notice that the usci_spi.cpp file for example hard codes references to channel B0 like register UCB0CTL1 and the like throughout. Quote Link to post Share on other sites
spirilis 1,265 Posted May 18, 2015 Share Posted May 18, 2015 I notice that the usci_spi.cpp file for example hard codes references to channel B0 like register UCB0CTL1 and the like throughout. Yup, in your cloned library change the name of the class (SPIClass in SPI.cpp and SPI.h) to something different e.g. SPIAClass, change the instantiation of SPI to something different like SPIA in SPI.h (search "extern SPIClass SPI;" and replace with "extern SPIAClass SPIA;" and in SPI.cpp, "SPIClass SPI;" becomes "SPIAClass SPIA;"), then modify the usci_spi.cpp in utility/ to replace all instances of "UCB" with "UCA". Quote Link to post Share on other sites
wnorcott 2 Posted May 18, 2015 Author Share Posted May 18, 2015 Thanks that confirms my doubts in that case I seemingly have to clone the pfatfs lib too since it includes SPI.h Quote Link to post Share on other sites
wnorcott 2 Posted May 19, 2015 Author Share Posted May 19, 2015 OK here is an update I seem to have got the thing working with SPI on USCA0 of the MSP430G2553. I just modified pins_energia.h and one file of the existing SPI library (usci_spi.cpp). By working I mean I can hook up my SD card module to the A0 channel and with this code I am successfully logging to the SD card using the (unmodified) pfatfs library. pins_energia.h I added a preprocessor flag #define SPI_USE_CHANNEL_A0 1 to remap the SPI pins constants // wnorcott 5/18/2015 // Uncomment the following ifdef to use USCI channel A0 instead // of B0 for SPI. That means you can use hardware SPI and I2C // simultaneously on the MSP430G2553 but you give up hardware // serial capability. The G2553 has two SPI channels A0 and B0. //#define SPI_USE_CHANNEL_A0 1 #define SPI_USE_CHANNEL_A0 1 #ifdef SPI_USE_CHANNEL_A0 static const uint8_t SS = 7; // P1.5 static const uint8_t SCK = 6; // P1.4 UCA0CLK static const uint8_t MOSI = 4; // P1.2 UCA0SIMO static const uint8_t MISO = 3; // P1.1 UCA0SOMI #else static const uint8_t SS = 8; /* P2.0 */ static const uint8_t SCK = 7; /* P1.5 */ static const uint8_t MOSI = 15; /* P1.7 */ static const uint8_t MISO = 14; /* P1.6 */ #endif changed SPI library module utility/usci_spi.cpp to test the new flag and variant the code to use channel A0: #ifdef SPI_USE_CHANNEL_A0 void spi_initialize(void) { UCA0CTL1 = UCSWRST | UCSSEL_2; // Put USCI in reset mode, source USCI clock from SMCLK UCA0CTL0 = SPI_MODE_0 | UCMSB | UCSYNC | UCMST; // Use SPI MODE 0 - CPOL=0 CPHA=0 pinMode_int(SCK, SPISCK_SET_MODE); pinMode_int(MOSI, SPIMOSI_SET_MODE); pinMode_int(MISO, SPIMISO_SET_MODE); UCA0BR0 = SPI_CLOCK_DIV() & 0xFF; // set initial speed to 4MHz UCA0BR1 = (SPI_CLOCK_DIV() >> 8 ) & 0xFF; UCA0CTL1 &= ~UCSWRST; // release USCI for operation } ... etc. in other words changed all the register references under the #ifdef to use USCI channel A0 hardware registers instead of channel B0. The methods I had to monkey with under the #ifdef were: spi_initialize, spi_disable, spi_send, spi_setdivisor, spi_set_bitorder, and spi_set_datamode. It would be nicer if it were possible (and maybe it is) to add the #define SPI_USE_CHANNEL_A0 1 in my own sketch or at least pass it as a -D flag to the compiler when I build the sketch, instead of having to define it in pins_energia.h Thanks again for your help. Fmilburn and cubeberg 2 Quote Link to post Share on other sites
AlanW 0 Posted November 14, 2015 Share Posted November 14, 2015 @@wnorcott @@spirilis I'm using the example code Enrf24_RXdemo, I need some pins for I2C as well. So I have to move to UCA0. I have some problems. I copied the SPI library to a new folder and let program includes it, it works fine. I changed all "UCB0" in usci_spi.cpp to "UCA0", and change pinMode_int(SCK, SPISCK_SET_MODE); pinMode_int(MOSI, SPIMOSI_SET_MODE); pinMode_int(MISO, SPIMISO_SET_MODE); to pinMode_int(6, SPISCK_SET_MODE); pinMode_int(4, SPIMOSI_SET_MODE); pinMode_int(3, SPIMISO_SET_MODE); it works fine for the first time but when I re-upload it to the board, it's not working anymore. I don't know why. I also tried have a new class, and name everything to SPIA, but It only word once like I mentioned above. (I only tested it once, I spend too much time on this, so I didn't try it again) I tired to change pinMode_int(SCK, SPISCK_SET_MODE); pinMode_int(MOSI, SPIMOSI_SET_MODE); pinMode_int(MISO, SPIMISO_SET_MODE); to pinMode_int(P1_4, SPISCK_SET_MODE); pinMode_int(P1_2, SPIMOSI_SET_MODE); pinMode_int(P1_1, SPIMISO_SET_MODE); It doesn't work. I tried to change SCK, MOSI, MISO in pins_energia.h and keep that in usci_spi.cpp. It doesn't work either. If I don't change the class name, in my code SPI.begin(); SPI.setDataMode(SPI_MODE0); SPI.setBitOrder(MSBFIRST); are those gonna run the code in the SPI library or run the code in the customize "SPIA" library? they have the same class name called SPI. Maybe it causing the problem but when I named a new class, it still not working. I'll appreciate it if you could give it a try, and maybe you know what's going on and have a solution for it. Thank you. Never mind. I figured it out. Quote Link to post Share on other sites
wangziru 0 Posted July 11, 2020 Share Posted July 11, 2020 I have the same problem,could you share the library about UCA0? Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.