Psii 0 Posted April 1, 2013 Share Posted April 1, 2013 I am using my MSP430F2012 as a slave to an Arduino. The arduino sends out the value 0x01 whenever I press "1" on the keyboard. So basically, what I want to do is have the MSP430 execute different operations depending on which value it receives from the master. In debug, mode I put a breakpoint in the cases where the value I read from USISRL is 0x01 and 0x02. The variable RxData (unsigned char) stores this value. The switch statement tests this variable and executes the appropriate operation. The problem is: Every second time I (odd numbers it seems) I press "1", RxData reads "2", although the USISRL register reads 0x01. I cannot seem to find a logical explanation for this, so I turn to the forums =). Does anyone have an idea what could be wrong here? // USI interrupt service routine #pragma vector=USI_VECTOR __interrupt void universal_serial_interface(void) { RxData = USISRL; USICNT = 8; switch(RxData) { case 1: // Breakpoint 1 break; case 2: // Breakpoint 2 break; } RxData = 0; } Also, I noticed that sometimes the MSP430 needs two sends from the master to trigger its interrupt routine. These times, RxData reads "2". The times RxData reads "1", only one send (button push) suffices. Quote Link to post Share on other sites
cubeberg 540 Posted April 1, 2013 Share Posted April 1, 2013 Any chance you're exceeding the SPI speed that the MSP430 will accept? The fact that it's missing transmissions, and getting bad data - sounds like that might be possible. Quote Link to post Share on other sites
Psii 0 Posted April 1, 2013 Author Share Posted April 1, 2013 Any chance you're exceeding the SPI speed that the MSP430 will accept? The fact that it's missing transmissions, and getting bad data - sounds like that might be possible. I guess it could be, because the data seems very unpredictable. On the other hand, the SPI clock is set to 16 MHz/128 = 125 kHz, so I don't think that could be the case. (2 hours later) I got it to work. The thing is that I am switching between using I2C and SPI on the same lines. The iniatilization of these interconnection standards were wrong. I went with using hexadecimal values instead of the library names when setting the USI registers, and it worked: void SPI_slaveInit(void) { // SPI USICTL0 = 0xE3; USICTL1 = 0x11; USICKCTL = 0x00; } void i2c_masterInit() { // I2C USICTL0 = 0xC9; // SCL | SDA | MASTER MODE | HOLD IN RESET STATE USICTL1 = 0x40; // I2C enable USICKCTL = 0xEA; // /128 = 93,5 kHz | SMCLK | Inverse SCL polarity } Quote Link to post Share on other sites
cubeberg 540 Posted April 1, 2013 Share Posted April 1, 2013 I guess it could be, because the data seems very unpredictable. On the other hand, the SPI clock is set to 16 MHz/128 = 125 kHz, so I don't think that could be the case. (2 hours later) I got it to work. The thing is that I am switching between using I2C and SPI on the same lines. The iniatilization of these interconnection standards were wrong. I went with using hexadecimal values instead of the library names when setting the USI registers, and it worked: void SPI_slaveInit(void) { // SPI USICTL0 = 0xE3; USICTL1 = 0x11; USICKCTL = 0x00; } void i2c_masterInit() { // I2C USICTL0 = 0xC9; // SCL | SDA | MASTER MODE | HOLD IN RESET STATE USICTL1 = 0x40; // I2C enable USICKCTL = 0xEA; // /128 = 93,5 kHz | SMCLK | Inverse SCL polarity } Ah - that would do it - you could explicitly turn off settings that were different between the two (&= ~) - most of the code samples available were probably only turning on bits (|=). 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.